src/js/libs/raphael.js
author hamidouk
Tue, 29 Nov 2011 11:09:08 +0100
branchpopcorn-port
changeset 345 8a088f7daa66
parent 168 a14343a9e897
permissions -rw-r--r--
rollover over the interface buttons now works as expected. Also changed the width of the buttons to the correct size. Resized the width and height of the sprites to be the same as the boxes we display them in.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
168
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
     1
// ┌─────────────────────────────────────────────────────────────────────┐ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
     2
// │ Raphaël 2.0 - JavaScript Vector Library                             │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
     3
// ├─────────────────────────────────────────────────────────────────────┤ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
     4
// │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com)   │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
     5
// │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com)             │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
     6
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
     7
// └─────────────────────────────────────────────────────────────────────┘ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
     8
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
     9
// ┌──────────────────────────────────────────────────────────────────────────────────────┐ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    10
// │ Eve 0.3.2 - JavaScript Events Library                                                │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    11
// ├──────────────────────────────────────────────────────────────────────────────────────┤ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    12
// │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://dmitry.baranovskiy.com/)          │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    13
// │ Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    14
// └──────────────────────────────────────────────────────────────────────────────────────┘ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    15
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    16
(function (glob) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    17
    var version = "0.3.2",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    18
        has = "hasOwnProperty",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    19
        separator = /[\.\/]/,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    20
        wildcard = "*",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    21
        fun = function () {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    22
        numsort = function (a, b) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    23
            return a - b;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    24
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    25
        current_event,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    26
        stop,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    27
        events = {n: {}},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    28
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    29
        eve = function (name, scope) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    30
            var e = events,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    31
                oldstop = stop,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    32
                args = Array.prototype.slice.call(arguments, 2),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    33
                listeners = eve.listeners(name),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    34
                z = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    35
                f = false,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    36
                l,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    37
                indexed = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    38
                queue = {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    39
                out = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    40
                errors = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    41
            current_event = name;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    42
            stop = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    43
            for (var i = 0, ii = listeners.length; i < ii; i++) if ("zIndex" in listeners[i]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    44
                indexed.push(listeners[i].zIndex);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    45
                if (listeners[i].zIndex < 0) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    46
                    queue[listeners[i].zIndex] = listeners[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    47
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    48
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    49
            indexed.sort(numsort);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    50
            while (indexed[z] < 0) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    51
                l = queue[indexed[z++]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    52
                out.push(l.apply(scope, args));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    53
                if (stop) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    54
                    stop = oldstop;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    55
                    return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    56
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    57
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    58
            for (i = 0; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    59
                l = listeners[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    60
                if ("zIndex" in l) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    61
                    if (l.zIndex == indexed[z]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    62
                        out.push(l.apply(scope, args));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    63
                        if (stop) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    64
                            stop = oldstop;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    65
                            return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    66
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    67
                        do {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    68
                            z++;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    69
                            l = queue[indexed[z]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    70
                            l && out.push(l.apply(scope, args));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    71
                            if (stop) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    72
                                stop = oldstop;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    73
                                return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    74
                            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    75
                        } while (l)
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    76
                    } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    77
                        queue[l.zIndex] = l;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    78
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    79
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    80
                    out.push(l.apply(scope, args));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    81
                    if (stop) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    82
                        stop = oldstop;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    83
                        return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    84
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    85
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    86
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    87
            stop = oldstop;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    88
            return out.length ? out : null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    89
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    90
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    91
    eve.listeners = function (name) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    92
        var names = name.split(separator),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    93
            e = events,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    94
            item,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    95
            items,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    96
            k,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    97
            i,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    98
            ii,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
    99
            j,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   100
            jj,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   101
            nes,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   102
            es = [e],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   103
            out = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   104
        for (i = 0, ii = names.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   105
            nes = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   106
            for (j = 0, jj = es.length; j < jj; j++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   107
                e = es[j].n;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   108
                items = [e[names[i]], e[wildcard]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   109
                k = 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   110
                while (k--) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   111
                    item = items[k];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   112
                    if (item) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   113
                        nes.push(item);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   114
                        out = out.concat(item.f || []);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   115
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   116
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   117
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   118
            es = nes;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   119
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   120
        return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   121
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   122
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   123
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   124
    eve.on = function (name, f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   125
        var names = name.split(separator),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   126
            e = events;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   127
        for (var i = 0, ii = names.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   128
            e = e.n;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   129
            !e[names[i]] && (e[names[i]] = {n: {}});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   130
            e = e[names[i]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   131
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   132
        e.f = e.f || [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   133
        for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   134
            return fun;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   135
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   136
        e.f.push(f);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   137
        return function (zIndex) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   138
            if (+zIndex == +zIndex) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   139
                f.zIndex = +zIndex;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   140
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   141
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   142
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   143
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   144
    eve.stop = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   145
        stop = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   146
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   147
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   148
    eve.nt = function (subname) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   149
        if (subname) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   150
            return new RegExp("(?:\\.|\\/|^)" + subname + "(?:\\.|\\/|$)").test(current_event);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   151
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   152
        return current_event;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   153
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   154
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   155
    eve.unbind = function (name, f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   156
        var names = name.split(separator),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   157
            e,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   158
            key,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   159
            splice,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   160
            cur = [events];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   161
        for (var i = 0, ii = names.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   162
            for (var j = 0; j < cur.length; j += splice.length - 2) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   163
                splice = [j, 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   164
                e = cur[j].n;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   165
                if (names[i] != wildcard) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   166
                    if (e[names[i]]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   167
                        splice.push(e[names[i]]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   168
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   169
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   170
                    for (key in e) if (e[has](key)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   171
                        splice.push(e[key]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   172
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   173
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   174
                cur.splice.apply(cur, splice);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   175
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   176
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   177
        for (i = 0, ii = cur.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   178
            e = cur[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   179
            while (e.n) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   180
                if (f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   181
                    if (e.f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   182
                        for (j = 0, jj = e.f.length; j < jj; j++) if (e.f[j] == f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   183
                            e.f.splice(j, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   184
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   185
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   186
                        !e.f.length && delete e.f;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   187
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   188
                    for (key in e.n) if (e.n[has](key) && e.n[key].f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   189
                        var funcs = e.n[key].f;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   190
                        for (j = 0, jj = funcs.length; j < jj; j++) if (funcs[j] == f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   191
                            funcs.splice(j, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   192
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   193
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   194
                        !funcs.length && delete e.n[key].f;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   195
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   196
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   197
                    delete e.f;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   198
                    for (key in e.n) if (e.n[has](key) && e.n[key].f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   199
                        delete e.n[key].f;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   200
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   201
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   202
                e = e.n;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   203
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   204
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   205
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   206
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   207
    eve.version = version;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   208
    eve.toString = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   209
        return "You are running Eve " + version;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   210
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   211
    (typeof module != "undefined" && module.exports) ? (module.exports = eve) : (glob.eve = eve);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   212
})(this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   213
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   214
// ┌─────────────────────────────────────────────────────────────────────┐ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   215
// │ "Raphaël 2.0" - JavaScript Vector Library                           │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   216
// ├─────────────────────────────────────────────────────────────────────┤ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   217
// │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com)   │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   218
// │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com)             │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   219
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   220
// └─────────────────────────────────────────────────────────────────────┘ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   221
(function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   222
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   223
    function R(first) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   224
        if (R.is(first, "function")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   225
            return loaded ? first() : eve.on("DOMload", first);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   226
        } else if (R.is(first, array)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   227
            var a = first,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   228
                cnv = R._engine.create[apply](R, a.splice(0, 3 + R.is(a[0], nu))),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   229
                res = cnv.set(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   230
                i = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   231
                ii = a.length,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   232
                j;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   233
            for (; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   234
                j = a[i] || {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   235
                elements[has](j.type) && res.push(cnv[j.type]().attr(j));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   236
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   237
            return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   238
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   239
            var args = Array.prototype.slice.call(arguments, 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   240
            if (R.is(args[args.length - 1], "function")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   241
                var f = args.pop();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   242
                return loaded ? f.call(R._engine.create[apply](R, args)) : eve.on("DOMload", function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   243
                    f.call(R._engine.create[apply](R, args));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   244
                });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   245
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   246
                return R._engine.create[apply](R, arguments);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   247
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   248
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   249
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   250
    R.version = "2.0.0";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   251
    R.eve = eve;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   252
    var loaded,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   253
        separator = /[, ]+/,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   254
        elements = {circle: 1, rect: 1, path: 1, ellipse: 1, text: 1, image: 1},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   255
        formatrg = /\{(\d+)\}/g,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   256
        proto = "prototype",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   257
        has = "hasOwnProperty",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   258
        g = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   259
            doc: document,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   260
            win: window
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   261
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   262
        oldRaphael = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   263
            was: Object.prototype[has].call(g.win, "Raphael"),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   264
            is: g.win.Raphael
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   265
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   266
        Paper = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   267
            
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   268
            
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   269
            this.ca = this.customAttributes = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   270
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   271
        paperproto,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   272
        appendChild = "appendChild",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   273
        apply = "apply",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   274
        concat = "concat",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   275
        supportsTouch = "createTouch" in g.doc,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   276
        E = "",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   277
        S = " ",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   278
        Str = String,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   279
        split = "split",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   280
        events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel"[split](S),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   281
        touchMap = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   282
            mousedown: "touchstart",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   283
            mousemove: "touchmove",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   284
            mouseup: "touchend"
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   285
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   286
        lowerCase = Str.prototype.toLowerCase,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   287
        math = Math,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   288
        mmax = math.max,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   289
        mmin = math.min,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   290
        abs = math.abs,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   291
        pow = math.pow,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   292
        PI = math.PI,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   293
        nu = "number",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   294
        string = "string",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   295
        array = "array",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   296
        toString = "toString",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   297
        fillString = "fill",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   298
        objectToString = Object.prototype.toString,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   299
        paper = {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   300
        push = "push",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   301
        ISURL = R._ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   302
        colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+%?)?)\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\))\s*$/i,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   303
        isnan = {"NaN": 1, "Infinity": 1, "-Infinity": 1},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   304
        bezierrg = /^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   305
        round = math.round,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   306
        setAttribute = "setAttribute",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   307
        toFloat = parseFloat,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   308
        toInt = parseInt,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   309
        upperCase = Str.prototype.toUpperCase,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   310
        availableAttrs = R._availableAttrs = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   311
            "arrow-end": "none",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   312
            "arrow-start": "none",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   313
            blur: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   314
            "clip-rect": "0 0 1e9 1e9",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   315
            cursor: "default",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   316
            cx: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   317
            cy: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   318
            fill: "#fff",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   319
            "fill-opacity": 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   320
            font: '10px "Arial"',
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   321
            "font-family": '"Arial"',
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   322
            "font-size": "10",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   323
            "font-style": "normal",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   324
            "font-weight": 400,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   325
            gradient: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   326
            height: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   327
            href: "http://raphaeljs.com/",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   328
            opacity: 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   329
            path: "M0,0",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   330
            r: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   331
            rx: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   332
            ry: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   333
            src: "",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   334
            stroke: "#000",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   335
            "stroke-dasharray": "",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   336
            "stroke-linecap": "butt",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   337
            "stroke-linejoin": "butt",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   338
            "stroke-miterlimit": 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   339
            "stroke-opacity": 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   340
            "stroke-width": 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   341
            target: "_blank",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   342
            "text-anchor": "middle",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   343
            title: "Raphael",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   344
            transform: "",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   345
            width: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   346
            x: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   347
            y: 0
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   348
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   349
        availableAnimAttrs = R._availableAnimAttrs = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   350
            blur: nu,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   351
            "clip-rect": "csv",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   352
            cx: nu,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   353
            cy: nu,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   354
            fill: "colour",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   355
            "fill-opacity": nu,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   356
            "font-size": nu,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   357
            height: nu,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   358
            opacity: nu,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   359
            path: "path",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   360
            r: nu,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   361
            rx: nu,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   362
            ry: nu,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   363
            stroke: "colour",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   364
            "stroke-opacity": nu,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   365
            "stroke-width": nu,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   366
            transform: "transform",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   367
            width: nu,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   368
            x: nu,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   369
            y: nu
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   370
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   371
        commaSpaces = /\s*,\s*/,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   372
        hsrg = {hs: 1, rg: 1},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   373
        p2s = /,?([achlmqrstvxz]),?/gi,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   374
        pathCommand = /([achlmrqstvz])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   375
        tCommand = /([rstm])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   376
        pathValues = /(-?\d*\.?\d*(?:e[\-+]?\d+)?)\s*,?\s*/ig,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   377
        radial_gradient = R._radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   378
        eldata = {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   379
        sortByKey = function (a, b) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   380
            return a.key - b.key;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   381
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   382
        sortByNumber = function (a, b) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   383
            return toFloat(a) - toFloat(b);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   384
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   385
        fun = function () {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   386
        pipe = function (x) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   387
            return x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   388
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   389
        rectPath = R._rectPath = function (x, y, w, h, r) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   390
            if (r) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   391
                return [["M", x + r, y], ["l", w - r * 2, 0], ["a", r, r, 0, 0, 1, r, r], ["l", 0, h - r * 2], ["a", r, r, 0, 0, 1, -r, r], ["l", r * 2 - w, 0], ["a", r, r, 0, 0, 1, -r, -r], ["l", 0, r * 2 - h], ["a", r, r, 0, 0, 1, r, -r], ["z"]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   392
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   393
            return [["M", x, y], ["l", w, 0], ["l", 0, h], ["l", -w, 0], ["z"]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   394
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   395
        ellipsePath = function (x, y, rx, ry) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   396
            if (ry == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   397
                ry = rx;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   398
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   399
            return [["M", x, y], ["m", 0, -ry], ["a", rx, ry, 0, 1, 1, 0, 2 * ry], ["a", rx, ry, 0, 1, 1, 0, -2 * ry], ["z"]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   400
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   401
        getPath = R._getPath = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   402
            path: function (el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   403
                return el.attr("path");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   404
            },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   405
            circle: function (el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   406
                var a = el.attrs;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   407
                return ellipsePath(a.cx, a.cy, a.r);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   408
            },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   409
            ellipse: function (el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   410
                var a = el.attrs;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   411
                return ellipsePath(a.cx, a.cy, a.rx, a.ry);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   412
            },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   413
            rect: function (el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   414
                var a = el.attrs;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   415
                return rectPath(a.x, a.y, a.width, a.height, a.r);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   416
            },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   417
            image: function (el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   418
                var a = el.attrs;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   419
                return rectPath(a.x, a.y, a.width, a.height);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   420
            },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   421
            text: function (el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   422
                var bbox = el._getBBox();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   423
                return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   424
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   425
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   426
        mapPath = R.mapPath = function (path, matrix) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   427
            if (!matrix) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   428
                return path;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   429
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   430
            var x, y, i, j, pathi;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   431
            path = path2curve(path);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   432
            for (i = 0, ii = path.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   433
                pathi = path[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   434
                for (j = 1, jj = pathi.length; j < jj; j += 2) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   435
                    x = matrix.x(pathi[j], pathi[j + 1]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   436
                    y = matrix.y(pathi[j], pathi[j + 1]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   437
                    pathi[j] = x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   438
                    pathi[j + 1] = y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   439
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   440
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   441
            return path;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   442
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   443
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   444
    R._g = g;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   445
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   446
    R.type = (g.win.SVGAngle || g.doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   447
    if (R.type == "VML") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   448
        var d = g.doc.createElement("div"),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   449
            b;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   450
        d.innerHTML = '<v:shape adj="1"/>';
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   451
        b = d.firstChild;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   452
        b.style.behavior = "url(#default#VML)";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   453
        if (!(b && typeof b.adj == "object")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   454
            return (R.type = E);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   455
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   456
        d = null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   457
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   458
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   459
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   460
    R.svg = !(R.vml = R.type == "VML");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   461
    R._Paper = Paper;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   462
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   463
    R.fn = paperproto = Paper.prototype = R.prototype;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   464
    R._id = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   465
    R._oid = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   466
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   467
    R.is = function (o, type) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   468
        type = lowerCase.call(type);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   469
        if (type == "finite") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   470
            return !isnan[has](+o);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   471
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   472
        if (type == "array") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   473
            return o instanceof Array;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   474
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   475
        return  (type == "null" && o === null) ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   476
                (type == typeof o && o !== null) ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   477
                (type == "object" && o === Object(o)) ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   478
                (type == "array" && Array.isArray && Array.isArray(o)) ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   479
                objectToString.call(o).slice(8, -1).toLowerCase() == type;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   480
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   481
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   482
    R.angle = function (x1, y1, x2, y2, x3, y3) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   483
        if (x3 == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   484
            var x = x1 - x2,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   485
                y = y1 - y2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   486
            if (!x && !y) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   487
                return 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   488
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   489
            return (180 + math.atan2(-y, -x) * 180 / PI + 360) % 360;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   490
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   491
            return R.angle(x1, y1, x3, y3) - R.angle(x2, y2, x3, y3);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   492
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   493
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   494
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   495
    R.rad = function (deg) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   496
        return deg % 360 * PI / 180;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   497
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   498
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   499
    R.deg = function (rad) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   500
        return rad * 180 / PI % 360;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   501
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   502
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   503
    R.snapTo = function (values, value, tolerance) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   504
        tolerance = R.is(tolerance, "finite") ? tolerance : 10;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   505
        if (R.is(values, array)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   506
            var i = values.length;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   507
            while (i--) if (abs(values[i] - value) <= tolerance) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   508
                return values[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   509
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   510
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   511
            values = +values;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   512
            var rem = value % values;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   513
            if (rem < tolerance) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   514
                return value - rem;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   515
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   516
            if (rem > values - tolerance) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   517
                return value - rem + values;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   518
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   519
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   520
        return value;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   521
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   522
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   523
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   524
    var createUUID = R.createUUID = (function (uuidRegEx, uuidReplacer) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   525
        return function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   526
            return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(uuidRegEx, uuidReplacer).toUpperCase();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   527
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   528
    })(/[xy]/g, function (c) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   529
        var r = math.random() * 16 | 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   530
            v = c == "x" ? r : (r & 3 | 8);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   531
        return v.toString(16);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   532
    });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   533
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   534
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   535
    R.setWindow = function (newwin) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   536
        eve("setWindow", R, g.win, newwin);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   537
        g.win = newwin;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   538
        g.doc = g.win.document;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   539
        if (initWin) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   540
            initWin(g.win);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   541
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   542
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   543
    var toHex = function (color) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   544
        if (R.vml) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   545
            // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   546
            var trim = /^\s+|\s+$/g;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   547
            var bod;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   548
            try {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   549
                var docum = new ActiveXObject("htmlfile");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   550
                docum.write("<body>");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   551
                docum.close();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   552
                bod = docum.body;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   553
            } catch(e) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   554
                bod = createPopup().document.body;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   555
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   556
            var range = bod.createTextRange();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   557
            toHex = cacher(function (color) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   558
                try {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   559
                    bod.style.color = Str(color).replace(trim, E);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   560
                    var value = range.queryCommandValue("ForeColor");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   561
                    value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   562
                    return "#" + ("000000" + value.toString(16)).slice(-6);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   563
                } catch(e) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   564
                    return "none";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   565
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   566
            });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   567
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   568
            var i = g.doc.createElement("i");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   569
            i.title = "Rapha\xebl Colour Picker";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   570
            i.style.display = "none";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   571
            g.doc.body.appendChild(i);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   572
            toHex = cacher(function (color) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   573
                i.style.color = color;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   574
                return g.doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   575
            });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   576
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   577
        return toHex(color);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   578
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   579
    hsbtoString = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   580
        return "hsb(" + [this.h, this.s, this.b] + ")";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   581
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   582
    hsltoString = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   583
        return "hsl(" + [this.h, this.s, this.l] + ")";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   584
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   585
    rgbtoString = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   586
        return this.hex;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   587
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   588
    prepareRGB = function (r, g, b) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   589
        if (g == null && R.is(r, "object") && "r" in r && "g" in r && "b" in r) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   590
            b = r.b;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   591
            g = r.g;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   592
            r = r.r;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   593
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   594
        if (g == null && R.is(r, string)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   595
            var clr = R.getRGB(r);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   596
            r = clr.r;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   597
            g = clr.g;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   598
            b = clr.b;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   599
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   600
        if (r > 1 || g > 1 || b > 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   601
            r /= 255;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   602
            g /= 255;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   603
            b /= 255;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   604
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   605
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   606
        return [r, g, b];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   607
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   608
    packageRGB = function (r, g, b, o) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   609
        r *= 255;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   610
        g *= 255;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   611
        b *= 255;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   612
        var rgb = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   613
            r: r,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   614
            g: g,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   615
            b: b,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   616
            hex: R.rgb(r, g, b),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   617
            toString: rgbtoString
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   618
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   619
        R.is(o, "finite") && (rgb.opacity = o);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   620
        return rgb;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   621
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   622
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   623
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   624
    R.color = function (clr) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   625
        var rgb;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   626
        if (R.is(clr, "object") && "h" in clr && "s" in clr && "b" in clr) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   627
            rgb = R.hsb2rgb(clr);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   628
            clr.r = rgb.r;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   629
            clr.g = rgb.g;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   630
            clr.b = rgb.b;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   631
            clr.hex = rgb.hex;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   632
        } else if (R.is(clr, "object") && "h" in clr && "s" in clr && "l" in clr) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   633
            rgb = R.hsl2rgb(clr);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   634
            clr.r = rgb.r;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   635
            clr.g = rgb.g;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   636
            clr.b = rgb.b;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   637
            clr.hex = rgb.hex;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   638
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   639
            if (R.is(clr, "string")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   640
                clr = R.getRGB(clr);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   641
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   642
            if (R.is(clr, "object") && "r" in clr && "g" in clr && "b" in clr) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   643
                rgb = R.rgb2hsl(clr);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   644
                clr.h = rgb.h;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   645
                clr.s = rgb.s;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   646
                clr.l = rgb.l;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   647
                rgb = R.rgb2hsb(clr);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   648
                clr.v = rgb.b;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   649
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   650
                clr = {hex: "none"};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   651
                crl.r = clr.g = clr.b = clr.h = clr.s = clr.v = clr.l = -1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   652
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   653
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   654
        clr.toString = rgbtoString;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   655
        return clr;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   656
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   657
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   658
    R.hsb2rgb = function (h, s, v, o) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   659
        if (this.is(h, "object") && "h" in h && "s" in h && "b" in h) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   660
            v = h.b;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   661
            s = h.s;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   662
            h = h.h;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   663
            o = h.o;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   664
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   665
        h *= 360;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   666
        var R, G, B, X, C;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   667
        h = (h % 360) / 60;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   668
        C = v * s;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   669
        X = C * (1 - abs(h % 2 - 1));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   670
        R = G = B = v - C;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   671
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   672
        h = ~~h;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   673
        R += [C, X, 0, 0, X, C][h];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   674
        G += [X, C, C, X, 0, 0][h];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   675
        B += [0, 0, X, C, C, X][h];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   676
        return packageRGB(R, G, B, o);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   677
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   678
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   679
    R.hsl2rgb = function (h, s, l, o) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   680
        if (this.is(h, "object") && "h" in h && "s" in h && "l" in h) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   681
            l = h.l;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   682
            s = h.s;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   683
            h = h.h;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   684
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   685
        if (h > 1 || s > 1 || l > 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   686
            h /= 360;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   687
            s /= 100;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   688
            l /= 100;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   689
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   690
        h *= 360;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   691
        var R, G, B, X, C;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   692
        h = (h % 360) / 60;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   693
        C = 2 * s * (l < .5 ? l : 1 - l);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   694
        X = C * (1 - abs(h % 2 - 1));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   695
        R = G = B = l - C / 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   696
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   697
        h = ~~h;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   698
        R += [C, X, 0, 0, X, C][h];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   699
        G += [X, C, C, X, 0, 0][h];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   700
        B += [0, 0, X, C, C, X][h];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   701
        return packageRGB(R, G, B, o);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   702
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   703
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   704
    R.rgb2hsb = function (r, g, b) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   705
        b = prepareRGB(r, g, b);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   706
        r = b[0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   707
        g = b[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   708
        b = b[2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   709
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   710
        var H, S, V, C;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   711
        V = mmax(r, g, b);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   712
        C = V - mmin(r, g, b);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   713
        H = (C == 0 ? null :
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   714
             V == r ? (g - b) / C :
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   715
             V == g ? (b - r) / C + 2 :
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   716
                      (r - g) / C + 4
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   717
            );
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   718
        H = ((H + 360) % 6) * 60 / 360;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   719
        S = C == 0 ? 0 : C / V;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   720
        return {h: H, s: S, b: V, toString: hsbtoString};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   721
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   722
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   723
    R.rgb2hsl = function (r, g, b) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   724
        b = prepareRGB(r, g, b);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   725
        r = b[0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   726
        g = b[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   727
        b = b[2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   728
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   729
        var H, S, L, M, m, C;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   730
        M = mmax(r, g, b);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   731
        m = mmin(r, g, b);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   732
        C = M - m;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   733
        H = (C == 0 ? null :
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   734
             M == r ? (g - b) / C :
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   735
             M == g ? (b - r) / C + 2 :
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   736
                      (r - g) / C + 4);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   737
        H = ((H + 360) % 6) * 60 / 360;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   738
        L = (M + m) / 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   739
        S = (C == 0 ? 0 :
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   740
             L < .5 ? C / (2 * L) :
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   741
                      C / (2 - 2 * L));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   742
        return {h: H, s: S, l: L, toString: hsltoString};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   743
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   744
    R._path2string = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   745
        return this.join(",").replace(p2s, "$1");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   746
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   747
    function repush(array, item) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   748
        for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   749
            return array.push(array.splice(i, 1)[0]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   750
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   751
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   752
    function cacher(f, scope, postprocessor) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   753
        function newf() {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   754
            var arg = Array.prototype.slice.call(arguments, 0),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   755
                args = arg.join("\u2400"),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   756
                cache = newf.cache = newf.cache || {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   757
                count = newf.count = newf.count || [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   758
            if (cache[has](args)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   759
                repush(count, args);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   760
                return postprocessor ? postprocessor(cache[args]) : cache[args];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   761
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   762
            count.length >= 1e3 && delete cache[count.shift()];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   763
            count.push(args);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   764
            cache[args] = f[apply](scope, arg);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   765
            return postprocessor ? postprocessor(cache[args]) : cache[args];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   766
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   767
        return newf;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   768
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   769
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   770
    var preload = R._preload = function (src, f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   771
        var img = g.doc.createElement("img");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   772
        img.style.cssText = "position:absolute;left:-9999em;top-9999em";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   773
        img.onload = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   774
            f.call(this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   775
            this.onload = null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   776
            g.doc.body.removeChild(this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   777
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   778
        img.onerror = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   779
            g.doc.body.removeChild(this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   780
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   781
        g.doc.body.appendChild(img);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   782
        img.src = src;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   783
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   784
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   785
    function clrToString() {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   786
        return this.hex;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   787
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   788
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   789
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   790
    R.getRGB = cacher(function (colour) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   791
        if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   792
            return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   793
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   794
        if (colour == "none") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   795
            return {r: -1, g: -1, b: -1, hex: "none", toString: clrToString};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   796
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   797
        !(hsrg[has](colour.toLowerCase().substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   798
        var res,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   799
            red,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   800
            green,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   801
            blue,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   802
            opacity,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   803
            t,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   804
            values,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   805
            rgb = colour.match(colourRegExp);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   806
        if (rgb) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   807
            if (rgb[2]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   808
                blue = toInt(rgb[2].substring(5), 16);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   809
                green = toInt(rgb[2].substring(3, 5), 16);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   810
                red = toInt(rgb[2].substring(1, 3), 16);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   811
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   812
            if (rgb[3]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   813
                blue = toInt((t = rgb[3].charAt(3)) + t, 16);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   814
                green = toInt((t = rgb[3].charAt(2)) + t, 16);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   815
                red = toInt((t = rgb[3].charAt(1)) + t, 16);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   816
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   817
            if (rgb[4]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   818
                values = rgb[4][split](commaSpaces);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   819
                red = toFloat(values[0]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   820
                values[0].slice(-1) == "%" && (red *= 2.55);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   821
                green = toFloat(values[1]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   822
                values[1].slice(-1) == "%" && (green *= 2.55);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   823
                blue = toFloat(values[2]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   824
                values[2].slice(-1) == "%" && (blue *= 2.55);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   825
                rgb[1].toLowerCase().slice(0, 4) == "rgba" && (opacity = toFloat(values[3]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   826
                values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   827
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   828
            if (rgb[5]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   829
                values = rgb[5][split](commaSpaces);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   830
                red = toFloat(values[0]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   831
                values[0].slice(-1) == "%" && (red *= 2.55);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   832
                green = toFloat(values[1]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   833
                values[1].slice(-1) == "%" && (green *= 2.55);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   834
                blue = toFloat(values[2]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   835
                values[2].slice(-1) == "%" && (blue *= 2.55);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   836
                (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   837
                rgb[1].toLowerCase().slice(0, 4) == "hsba" && (opacity = toFloat(values[3]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   838
                values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   839
                return R.hsb2rgb(red, green, blue, opacity);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   840
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   841
            if (rgb[6]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   842
                values = rgb[6][split](commaSpaces);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   843
                red = toFloat(values[0]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   844
                values[0].slice(-1) == "%" && (red *= 2.55);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   845
                green = toFloat(values[1]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   846
                values[1].slice(-1) == "%" && (green *= 2.55);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   847
                blue = toFloat(values[2]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   848
                values[2].slice(-1) == "%" && (blue *= 2.55);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   849
                (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   850
                rgb[1].toLowerCase().slice(0, 4) == "hsla" && (opacity = toFloat(values[3]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   851
                values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   852
                return R.hsl2rgb(red, green, blue, opacity);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   853
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   854
            rgb = {r: red, g: green, b: blue, toString: clrToString};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   855
            rgb.hex = "#" + (16777216 | blue | (green << 8) | (red << 16)).toString(16).slice(1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   856
            R.is(opacity, "finite") && (rgb.opacity = opacity);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   857
            return rgb;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   858
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   859
        return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   860
    }, R);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   861
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   862
    R.hsb = cacher(function (h, s, b) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   863
        return R.hsb2rgb(h, s, b).hex;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   864
    });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   865
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   866
    R.hsl = cacher(function (h, s, l) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   867
        return R.hsl2rgb(h, s, l).hex;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   868
    });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   869
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   870
    R.rgb = cacher(function (r, g, b) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   871
        return "#" + (16777216 | b | (g << 8) | (r << 16)).toString(16).slice(1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   872
    });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   873
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   874
    R.getColor = function (value) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   875
        var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   876
            rgb = this.hsb2rgb(start.h, start.s, start.b);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   877
        start.h += .075;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   878
        if (start.h > 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   879
            start.h = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   880
            start.s -= .2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   881
            start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   882
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   883
        return rgb.hex;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   884
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   885
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   886
    R.getColor.reset = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   887
        delete this.start;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   888
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   889
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   890
    // http://schepers.cc/getting-to-the-point
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   891
    function catmullRom2bezier(crp) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   892
        var d = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   893
        for (var i = 0, iLen = crp.length; iLen - 2 > i; i += 2) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   894
            var p = [{x: +crp[i],     y: +crp[i + 1]},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   895
                     {x: +crp[i],     y: +crp[i + 1]},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   896
                     {x: +crp[i + 2], y: +crp[i + 3]},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   897
                     {x: +crp[i + 4], y: +crp[i + 5]}];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   898
            if (iLen - 4 == i) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   899
                p[0] = {x: +crp[i - 2], y: +crp[i - 1]};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   900
                p[3] = p[2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   901
            } else if (i) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   902
                p[0] = {x: +crp[i - 2], y: +crp[i - 1]};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   903
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   904
            d.push(["C",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   905
                (-p[0].x + 6 * p[1].x + p[2].x) / 6,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   906
                (-p[0].y + 6 * p[1].y + p[2].y) / 6,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   907
                (p[1].x + 6 * p[2].x - p[3].x) / 6,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   908
                (p[1].y + 6*p[2].y - p[3].y) / 6,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   909
                p[2].x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   910
                p[2].y
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   911
            ]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   912
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   913
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   914
        return d;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   915
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   916
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   917
    R.parsePathString = cacher(function (pathString) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   918
        if (!pathString) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   919
            return null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   920
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   921
        var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, z: 0},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   922
            data = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   923
        if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   924
            data = pathClone(pathString);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   925
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   926
        if (!data.length) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   927
            Str(pathString).replace(pathCommand, function (a, b, c) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   928
                var params = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   929
                    name = b.toLowerCase();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   930
                c.replace(pathValues, function (a, b) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   931
                    b && params.push(+b);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   932
                });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   933
                if (name == "m" && params.length > 2) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   934
                    data.push([b][concat](params.splice(0, 2)));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   935
                    name = "l";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   936
                    b = b == "m" ? "l" : "L";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   937
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   938
                if (name == "r") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   939
                    data.push([b][concat](params));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   940
                } else while (params.length >= paramCounts[name]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   941
                    data.push([b][concat](params.splice(0, paramCounts[name])));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   942
                    if (!paramCounts[name]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   943
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   944
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   945
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   946
            });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   947
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   948
        data.toString = R._path2string;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   949
        return data;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   950
    });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   951
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   952
    R.parseTransformString = cacher(function (TString) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   953
        if (!TString) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   954
            return null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   955
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   956
        var paramCounts = {r: 3, s: 4, t: 2, m: 6},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   957
            data = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   958
        if (R.is(TString, array) && R.is(TString[0], array)) { // rough assumption
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   959
            data = pathClone(TString);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   960
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   961
        if (!data.length) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   962
            Str(TString).replace(tCommand, function (a, b, c) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   963
                var params = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   964
                    name = lowerCase.call(b);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   965
                c.replace(pathValues, function (a, b) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   966
                    b && params.push(+b);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   967
                });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   968
                data.push([b][concat](params));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   969
            });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   970
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   971
        data.toString = R._path2string;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   972
        return data;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   973
    });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   974
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   975
    R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   976
        var t1 = 1 - t,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   977
            t13 = pow(t1, 3),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   978
            t12 = pow(t1, 2),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   979
            t2 = t * t,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   980
            t3 = t2 * t,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   981
            x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   982
            y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   983
            mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   984
            my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   985
            nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   986
            ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   987
            ax = t1 * p1x + t * c1x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   988
            ay = t1 * p1y + t * c1y,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   989
            cx = t1 * c2x + t * p2x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   990
            cy = t1 * c2y + t * p2y,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   991
            alpha = (90 - math.atan2(mx - nx, my - ny) * 180 / PI);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   992
        (mx > nx || my < ny) && (alpha += 180);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   993
        return {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   994
            x: x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   995
            y: y,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   996
            m: {x: mx, y: my},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   997
            n: {x: nx, y: ny},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   998
            start: {x: ax, y: ay},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
   999
            end: {x: cx, y: cy},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1000
            alpha: alpha
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1001
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1002
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1003
    var pathDimensions = cacher(function (path) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1004
        if (!path) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1005
            return {x: 0, y: 0, width: 0, height: 0};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1006
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1007
        path = path2curve(path);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1008
        var x = 0, 
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1009
            y = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1010
            X = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1011
            Y = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1012
            p;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1013
        for (var i = 0, ii = path.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1014
            p = path[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1015
            if (p[0] == "M") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1016
                x = p[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1017
                y = p[2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1018
                X.push(x);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1019
                Y.push(y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1020
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1021
                var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1022
                X = X[concat](dim.min.x, dim.max.x);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1023
                Y = Y[concat](dim.min.y, dim.max.y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1024
                x = p[5];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1025
                y = p[6];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1026
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1027
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1028
        var xmin = mmin[apply](0, X),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1029
            ymin = mmin[apply](0, Y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1030
        return {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1031
            x: xmin,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1032
            y: ymin,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1033
            width: mmax[apply](0, X) - xmin,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1034
            height: mmax[apply](0, Y) - ymin
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1035
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1036
    }, null, function (o) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1037
        return {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1038
            x: o.x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1039
            y: o.y,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1040
            width: o.width,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1041
            height: o.height
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1042
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1043
    }),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1044
        pathClone = function (pathArray) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1045
            var res = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1046
            if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1047
                pathArray = R.parsePathString(pathArray);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1048
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1049
            for (var i = 0, ii = pathArray.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1050
                res[i] = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1051
                for (var j = 0, jj = pathArray[i].length; j < jj; j++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1052
                    res[i][j] = pathArray[i][j];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1053
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1054
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1055
            res.toString = R._path2string;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1056
            return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1057
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1058
        pathToRelative = R._pathToRelative = cacher(function (pathArray) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1059
            if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1060
                pathArray = R.parsePathString(pathArray);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1061
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1062
            var res = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1063
                x = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1064
                y = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1065
                mx = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1066
                my = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1067
                start = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1068
            if (pathArray[0][0] == "M") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1069
                x = pathArray[0][1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1070
                y = pathArray[0][2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1071
                mx = x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1072
                my = y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1073
                start++;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1074
                res.push(["M", x, y]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1075
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1076
            for (var i = start, ii = pathArray.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1077
                var r = res[i] = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1078
                    pa = pathArray[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1079
                if (pa[0] != lowerCase.call(pa[0])) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1080
                    r[0] = lowerCase.call(pa[0]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1081
                    switch (r[0]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1082
                        case "a":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1083
                            r[1] = pa[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1084
                            r[2] = pa[2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1085
                            r[3] = pa[3];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1086
                            r[4] = pa[4];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1087
                            r[5] = pa[5];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1088
                            r[6] = +(pa[6] - x).toFixed(3);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1089
                            r[7] = +(pa[7] - y).toFixed(3);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1090
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1091
                        case "v":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1092
                            r[1] = +(pa[1] - y).toFixed(3);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1093
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1094
                        case "m":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1095
                            mx = pa[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1096
                            my = pa[2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1097
                        default:
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1098
                            for (var j = 1, jj = pa.length; j < jj; j++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1099
                                r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1100
                            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1101
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1102
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1103
                    r = res[i] = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1104
                    if (pa[0] == "m") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1105
                        mx = pa[1] + x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1106
                        my = pa[2] + y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1107
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1108
                    for (var k = 0, kk = pa.length; k < kk; k++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1109
                        res[i][k] = pa[k];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1110
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1111
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1112
                var len = res[i].length;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1113
                switch (res[i][0]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1114
                    case "z":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1115
                        x = mx;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1116
                        y = my;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1117
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1118
                    case "h":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1119
                        x += +res[i][len - 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1120
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1121
                    case "v":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1122
                        y += +res[i][len - 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1123
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1124
                    default:
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1125
                        x += +res[i][len - 2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1126
                        y += +res[i][len - 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1127
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1128
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1129
            res.toString = R._path2string;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1130
            return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1131
        }, 0, pathClone),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1132
        pathToAbsolute = R._pathToAbsolute = cacher(function (pathArray) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1133
            if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1134
                pathArray = R.parsePathString(pathArray);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1135
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1136
            if (!pathArray || !pathArray.length) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1137
                return [["M", 0, 0]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1138
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1139
            var res = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1140
                x = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1141
                y = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1142
                mx = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1143
                my = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1144
                start = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1145
            if (pathArray[0][0] == "M") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1146
                x = +pathArray[0][1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1147
                y = +pathArray[0][2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1148
                mx = x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1149
                my = y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1150
                start++;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1151
                res[0] = ["M", x, y];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1152
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1153
            for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1154
                res.push(r = []);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1155
                pa = pathArray[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1156
                if (pa[0] != upperCase.call(pa[0])) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1157
                    r[0] = upperCase.call(pa[0]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1158
                    switch (r[0]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1159
                        case "A":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1160
                            r[1] = pa[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1161
                            r[2] = pa[2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1162
                            r[3] = pa[3];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1163
                            r[4] = pa[4];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1164
                            r[5] = pa[5];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1165
                            r[6] = +(pa[6] + x);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1166
                            r[7] = +(pa[7] + y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1167
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1168
                        case "V":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1169
                            r[1] = +pa[1] + y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1170
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1171
                        case "H":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1172
                            r[1] = +pa[1] + x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1173
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1174
                        case "R":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1175
                            var dots = [x, y][concat](pa.slice(1));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1176
                            for (var j = 2, jj = dots.length; j < jj; j++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1177
                                dots[j] = +dots[j] + x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1178
                                dots[++j] = +dots[j] + y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1179
                            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1180
                            res.pop();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1181
                            res = res[concat](catmullRom2bezier(dots));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1182
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1183
                        case "M":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1184
                            mx = +pa[1] + x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1185
                            my = +pa[2] + y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1186
                        default:
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1187
                            for (j = 1, jj = pa.length; j < jj; j++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1188
                                r[j] = +pa[j] + ((j % 2) ? x : y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1189
                            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1190
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1191
                } else if (pa[0] == "R") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1192
                    dots = [x, y][concat](pa.slice(1));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1193
                    res.pop();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1194
                    res = res[concat](catmullRom2bezier(dots));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1195
                    r = ["R"][concat](pa.slice(-2));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1196
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1197
                    for (var k = 0, kk = pa.length; k < kk; k++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1198
                        r[k] = pa[k];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1199
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1200
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1201
                switch (r[0]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1202
                    case "Z":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1203
                        x = mx;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1204
                        y = my;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1205
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1206
                    case "H":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1207
                        x = r[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1208
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1209
                    case "V":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1210
                        y = r[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1211
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1212
                    case "M":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1213
                        mx = r[r.length - 2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1214
                        my = r[r.length - 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1215
                    default:
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1216
                        x = r[r.length - 2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1217
                        y = r[r.length - 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1218
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1219
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1220
            res.toString = R._path2string;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1221
            return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1222
        }, null, pathClone),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1223
        l2c = function (x1, y1, x2, y2) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1224
            return [x1, y1, x2, y2, x2, y2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1225
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1226
        q2c = function (x1, y1, ax, ay, x2, y2) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1227
            var _13 = 1 / 3,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1228
                _23 = 2 / 3;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1229
            return [
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1230
                    _13 * x1 + _23 * ax,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1231
                    _13 * y1 + _23 * ay,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1232
                    _13 * x2 + _23 * ax,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1233
                    _13 * y2 + _23 * ay,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1234
                    x2,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1235
                    y2
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1236
                ];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1237
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1238
        a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1239
            // for more information of where this math came from visit:
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1240
            // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1241
            var _120 = PI * 120 / 180,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1242
                rad = PI / 180 * (+angle || 0),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1243
                res = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1244
                xy,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1245
                rotate = cacher(function (x, y, rad) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1246
                    var X = x * math.cos(rad) - y * math.sin(rad),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1247
                        Y = x * math.sin(rad) + y * math.cos(rad);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1248
                    return {x: X, y: Y};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1249
                });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1250
            if (!recursive) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1251
                xy = rotate(x1, y1, -rad);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1252
                x1 = xy.x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1253
                y1 = xy.y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1254
                xy = rotate(x2, y2, -rad);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1255
                x2 = xy.x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1256
                y2 = xy.y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1257
                var cos = math.cos(PI / 180 * angle),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1258
                    sin = math.sin(PI / 180 * angle),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1259
                    x = (x1 - x2) / 2,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1260
                    y = (y1 - y2) / 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1261
                var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1262
                if (h > 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1263
                    h = math.sqrt(h);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1264
                    rx = h * rx;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1265
                    ry = h * ry;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1266
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1267
                var rx2 = rx * rx,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1268
                    ry2 = ry * ry,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1269
                    k = (large_arc_flag == sweep_flag ? -1 : 1) *
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1270
                        math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1271
                    cx = k * rx * y / ry + (x1 + x2) / 2,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1272
                    cy = k * -ry * x / rx + (y1 + y2) / 2,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1273
                    f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1274
                    f2 = math.asin(((y2 - cy) / ry).toFixed(9));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1275
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1276
                f1 = x1 < cx ? PI - f1 : f1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1277
                f2 = x2 < cx ? PI - f2 : f2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1278
                f1 < 0 && (f1 = PI * 2 + f1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1279
                f2 < 0 && (f2 = PI * 2 + f2);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1280
                if (sweep_flag && f1 > f2) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1281
                    f1 = f1 - PI * 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1282
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1283
                if (!sweep_flag && f2 > f1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1284
                    f2 = f2 - PI * 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1285
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1286
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1287
                f1 = recursive[0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1288
                f2 = recursive[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1289
                cx = recursive[2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1290
                cy = recursive[3];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1291
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1292
            var df = f2 - f1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1293
            if (abs(df) > _120) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1294
                var f2old = f2,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1295
                    x2old = x2,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1296
                    y2old = y2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1297
                f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1298
                x2 = cx + rx * math.cos(f2);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1299
                y2 = cy + ry * math.sin(f2);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1300
                res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1301
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1302
            df = f2 - f1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1303
            var c1 = math.cos(f1),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1304
                s1 = math.sin(f1),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1305
                c2 = math.cos(f2),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1306
                s2 = math.sin(f2),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1307
                t = math.tan(df / 4),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1308
                hx = 4 / 3 * rx * t,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1309
                hy = 4 / 3 * ry * t,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1310
                m1 = [x1, y1],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1311
                m2 = [x1 + hx * s1, y1 - hy * c1],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1312
                m3 = [x2 + hx * s2, y2 - hy * c2],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1313
                m4 = [x2, y2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1314
            m2[0] = 2 * m1[0] - m2[0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1315
            m2[1] = 2 * m1[1] - m2[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1316
            if (recursive) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1317
                return [m2, m3, m4][concat](res);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1318
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1319
                res = [m2, m3, m4][concat](res).join()[split](",");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1320
                var newres = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1321
                for (var i = 0, ii = res.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1322
                    newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1323
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1324
                return newres;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1325
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1326
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1327
        findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1328
            var t1 = 1 - t;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1329
            return {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1330
                x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1331
                y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1332
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1333
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1334
        curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1335
            var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1336
                b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1337
                c = p1x - c1x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1338
                t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1339
                t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1340
                y = [p1y, p2y],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1341
                x = [p1x, p2x],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1342
                dot;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1343
            abs(t1) > "1e12" && (t1 = .5);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1344
            abs(t2) > "1e12" && (t2 = .5);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1345
            if (t1 > 0 && t1 < 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1346
                dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1347
                x.push(dot.x);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1348
                y.push(dot.y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1349
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1350
            if (t2 > 0 && t2 < 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1351
                dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1352
                x.push(dot.x);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1353
                y.push(dot.y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1354
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1355
            a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1356
            b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1357
            c = p1y - c1y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1358
            t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1359
            t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1360
            abs(t1) > "1e12" && (t1 = .5);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1361
            abs(t2) > "1e12" && (t2 = .5);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1362
            if (t1 > 0 && t1 < 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1363
                dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1364
                x.push(dot.x);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1365
                y.push(dot.y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1366
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1367
            if (t2 > 0 && t2 < 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1368
                dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1369
                x.push(dot.x);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1370
                y.push(dot.y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1371
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1372
            return {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1373
                min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1374
                max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1375
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1376
        }),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1377
        path2curve = R._path2curve = cacher(function (path, path2) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1378
            var p = pathToAbsolute(path),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1379
                p2 = path2 && pathToAbsolute(path2),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1380
                attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1381
                attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1382
                processPath = function (path, d) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1383
                    var nx, ny;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1384
                    if (!path) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1385
                        return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1386
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1387
                    !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1388
                    switch (path[0]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1389
                        case "M":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1390
                            d.X = path[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1391
                            d.Y = path[2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1392
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1393
                        case "A":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1394
                            path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1395
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1396
                        case "S":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1397
                            nx = d.x + (d.x - (d.bx || d.x));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1398
                            ny = d.y + (d.y - (d.by || d.y));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1399
                            path = ["C", nx, ny][concat](path.slice(1));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1400
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1401
                        case "T":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1402
                            d.qx = d.x + (d.x - (d.qx || d.x));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1403
                            d.qy = d.y + (d.y - (d.qy || d.y));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1404
                            path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1405
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1406
                        case "Q":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1407
                            d.qx = path[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1408
                            d.qy = path[2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1409
                            path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1410
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1411
                        case "L":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1412
                            path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1413
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1414
                        case "H":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1415
                            path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1416
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1417
                        case "V":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1418
                            path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1419
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1420
                        case "Z":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1421
                            path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1422
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1423
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1424
                    return path;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1425
                },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1426
                fixArc = function (pp, i) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1427
                    if (pp[i].length > 7) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1428
                        pp[i].shift();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1429
                        var pi = pp[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1430
                        while (pi.length) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1431
                            pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1432
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1433
                        pp.splice(i, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1434
                        ii = mmax(p.length, p2 && p2.length || 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1435
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1436
                },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1437
                fixM = function (path1, path2, a1, a2, i) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1438
                    if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1439
                        path2.splice(i, 0, ["M", a2.x, a2.y]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1440
                        a1.bx = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1441
                        a1.by = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1442
                        a1.x = path1[i][1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1443
                        a1.y = path1[i][2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1444
                        ii = mmax(p.length, p2 && p2.length || 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1445
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1446
                };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1447
            for (var i = 0, ii = mmax(p.length, p2 && p2.length || 0); i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1448
                p[i] = processPath(p[i], attrs);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1449
                fixArc(p, i);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1450
                p2 && (p2[i] = processPath(p2[i], attrs2));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1451
                p2 && fixArc(p2, i);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1452
                fixM(p, p2, attrs, attrs2, i);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1453
                fixM(p2, p, attrs2, attrs, i);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1454
                var seg = p[i],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1455
                    seg2 = p2 && p2[i],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1456
                    seglen = seg.length,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1457
                    seg2len = p2 && seg2.length;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1458
                attrs.x = seg[seglen - 2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1459
                attrs.y = seg[seglen - 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1460
                attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1461
                attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1462
                attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1463
                attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1464
                attrs2.x = p2 && seg2[seg2len - 2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1465
                attrs2.y = p2 && seg2[seg2len - 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1466
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1467
            return p2 ? [p, p2] : p;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1468
        }, null, pathClone),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1469
        parseDots = R._parseDots = cacher(function (gradient) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1470
            var dots = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1471
            for (var i = 0, ii = gradient.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1472
                var dot = {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1473
                    par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1474
                dot.color = R.getRGB(par[1]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1475
                if (dot.color.error) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1476
                    return null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1477
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1478
                dot.color = dot.color.hex;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1479
                par[2] && (dot.offset = par[2] + "%");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1480
                dots.push(dot);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1481
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1482
            for (i = 1, ii = dots.length - 1; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1483
                if (!dots[i].offset) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1484
                    var start = toFloat(dots[i - 1].offset || 0),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1485
                        end = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1486
                    for (var j = i + 1; j < ii; j++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1487
                        if (dots[j].offset) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1488
                            end = dots[j].offset;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1489
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1490
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1491
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1492
                    if (!end) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1493
                        end = 100;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1494
                        j = ii;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1495
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1496
                    end = toFloat(end);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1497
                    var d = (end - start) / (j - i + 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1498
                    for (; i < j; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1499
                        start += d;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1500
                        dots[i].offset = start + "%";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1501
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1502
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1503
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1504
            return dots;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1505
        }),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1506
        tear = R._tear = function (el, paper) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1507
            el == paper.top && (paper.top = el.prev);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1508
            el == paper.bottom && (paper.bottom = el.next);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1509
            el.next && (el.next.prev = el.prev);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1510
            el.prev && (el.prev.next = el.next);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1511
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1512
        tofront = R._tofront = function (el, paper) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1513
            if (paper.top === el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1514
                return;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1515
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1516
            tear(el, paper);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1517
            el.next = null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1518
            el.prev = paper.top;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1519
            paper.top.next = el;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1520
            paper.top = el;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1521
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1522
        toback = R._toback = function (el, paper) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1523
            if (paper.bottom === el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1524
                return;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1525
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1526
            tear(el, paper);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1527
            el.next = paper.bottom;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1528
            el.prev = null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1529
            paper.bottom.prev = el;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1530
            paper.bottom = el;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1531
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1532
        insertafter = R._insertafter = function (el, el2, paper) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1533
            tear(el, paper);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1534
            el2 == paper.top && (paper.top = el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1535
            el2.next && (el2.next.prev = el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1536
            el.next = el2.next;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1537
            el.prev = el2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1538
            el2.next = el;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1539
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1540
        insertbefore = R._insertbefore = function (el, el2, paper) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1541
            tear(el, paper);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1542
            el2 == paper.bottom && (paper.bottom = el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1543
            el2.prev && (el2.prev.next = el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1544
            el.prev = el2.prev;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1545
            el2.prev = el;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1546
            el.next = el2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1547
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1548
        removed = function (methodname) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1549
            return function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1550
                throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1551
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1552
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1553
        extractTransform = R._extractTransform = function (el, tstr) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1554
            if (tstr == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1555
                return el._.transform;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1556
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1557
            tstr = Str(tstr).replace(/\.{3}|\u2026/g, el._.transform || E);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1558
            var tdata = R.parseTransformString(tstr),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1559
                deg = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1560
                dx = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1561
                dy = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1562
                sx = 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1563
                sy = 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1564
                _ = el._,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1565
                m = new Matrix;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1566
            _.transform = tdata || [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1567
            if (tdata) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1568
                for (var i = 0, ii = tdata.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1569
                    var t = tdata[i],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1570
                        tlen = t.length,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1571
                        command = Str(t[0]).toLowerCase(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1572
                        absolute = t[0] != command,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1573
                        inver = absolute ? m.invert() : 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1574
                        x1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1575
                        y1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1576
                        x2,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1577
                        y2,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1578
                        bb;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1579
                    if (command == "t" && tlen == 3) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1580
                        if (absolute) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1581
                            x1 = inver.x(0, 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1582
                            y1 = inver.y(0, 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1583
                            x2 = inver.x(t[1], t[2]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1584
                            y2 = inver.y(t[1], t[2]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1585
                            m.translate(x2 - x1, y2 - y1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1586
                        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1587
                            m.translate(t[1], t[2]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1588
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1589
                    } else if (command == "r") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1590
                        if (tlen == 2) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1591
                            bb = bb || el.getBBox(1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1592
                            m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1593
                            deg += t[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1594
                        } else if (tlen == 4) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1595
                            if (absolute) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1596
                                x2 = inver.x(t[2], t[3]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1597
                                y2 = inver.y(t[2], t[3]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1598
                                m.rotate(t[1], x2, y2);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1599
                            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1600
                                m.rotate(t[1], t[2], t[3]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1601
                            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1602
                            deg += t[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1603
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1604
                    } else if (command == "s") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1605
                        if (tlen == 2 || tlen == 3) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1606
                            bb = bb || el.getBBox(1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1607
                            m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1608
                            sx *= t[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1609
                            sy *= t[tlen - 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1610
                        } else if (tlen == 5) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1611
                            if (absolute) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1612
                                x2 = inver.x(t[3], t[4]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1613
                                y2 = inver.y(t[3], t[4]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1614
                                m.scale(t[1], t[2], x2, y2);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1615
                            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1616
                                m.scale(t[1], t[2], t[3], t[4]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1617
                            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1618
                            sx *= t[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1619
                            sy *= t[2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1620
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1621
                    } else if (command == "m" && tlen == 7) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1622
                        m.add(t[1], t[2], t[3], t[4], t[5], t[6]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1623
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1624
                    _.dirtyT = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1625
                    el.matrix = m;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1626
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1627
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1628
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1629
            el.matrix = m;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1630
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1631
            _.sx = sx;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1632
            _.sy = sy;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1633
            _.deg = deg;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1634
            _.dx = dx = m.e;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1635
            _.dy = dy = m.f;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1636
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1637
            if (sx == 1 && sy == 1 && !deg && _.bbox) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1638
                _.bbox.x += +dx;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1639
                _.bbox.y += +dy;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1640
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1641
                _.dirtyT = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1642
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1643
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1644
        getEmpty = function (item) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1645
            var l = item[0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1646
            switch (l.toLowerCase()) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1647
                case "t": return [l, 0, 0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1648
                case "m": return [l, 1, 0, 0, 1, 0, 0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1649
                case "r": if (item.length == 4) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1650
                    return [l, 0, item[2], item[3]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1651
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1652
                    return [l, 0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1653
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1654
                case "s": if (item.length == 5) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1655
                    return [l, 1, 1, item[3], item[4]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1656
                } else if (item.length == 3) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1657
                    return [l, 1, 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1658
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1659
                    return [l, 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1660
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1661
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1662
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1663
        equaliseTransform = R._equaliseTransform = function (t1, t2) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1664
            t2 = Str(t2).replace(/\.{3}|\u2026/g, t1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1665
            t1 = R.parseTransformString(t1) || [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1666
            t2 = R.parseTransformString(t2) || [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1667
            var maxlength = mmax(t1.length, t2.length),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1668
                from = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1669
                to = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1670
                i = 0, j, jj,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1671
                tt1, tt2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1672
            for (; i < maxlength; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1673
                tt1 = t1[i] || getEmpty(t2[i]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1674
                tt2 = t2[i] || getEmpty(tt1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1675
                if ((tt1[0] != tt2[0]) ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1676
                    (tt1[0].toLowerCase() == "r" && (tt1[2] != tt2[2] || tt1[3] != tt2[3])) ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1677
                    (tt1[0].toLowerCase() == "s" && (tt1[3] != tt2[3] || tt1[4] != tt2[4]))
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1678
                    ) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1679
                    return;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1680
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1681
                from[i] = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1682
                to[i] = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1683
                for (j = 0, jj = mmax(tt1.length, tt2.length); j < jj; j++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1684
                    j in tt1 && (from[i][j] = tt1[j]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1685
                    j in tt2 && (to[i][j] = tt2[j]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1686
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1687
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1688
            return {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1689
                from: from,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1690
                to: to
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1691
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1692
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1693
    R._getContainer = function (x, y, w, h) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1694
        var container;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1695
        container = h == null && !R.is(x, "object") ? g.doc.getElementById(x) : x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1696
        if (container == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1697
            return;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1698
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1699
        if (container.tagName) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1700
            if (y == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1701
                return {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1702
                    container: container,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1703
                    width: container.style.pixelWidth || container.offsetWidth,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1704
                    height: container.style.pixelHeight || container.offsetHeight
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1705
                };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1706
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1707
                return {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1708
                    container: container,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1709
                    width: y,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1710
                    height: w
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1711
                };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1712
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1713
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1714
        return {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1715
            container: 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1716
            x: x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1717
            y: y,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1718
            width: w,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1719
            height: h
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1720
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1721
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1722
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1723
    R.pathToRelative = pathToRelative;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1724
    R._engine = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1725
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1726
    R.path2curve = path2curve;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1727
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1728
    R.matrix = function (a, b, c, d, e, f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1729
        return new Matrix(a, b, c, d, e, f);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1730
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1731
    function Matrix(a, b, c, d, e, f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1732
        if (a != null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1733
            this.a = +a;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1734
            this.b = +b;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1735
            this.c = +c;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1736
            this.d = +d;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1737
            this.e = +e;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1738
            this.f = +f;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1739
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1740
            this.a = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1741
            this.b = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1742
            this.c = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1743
            this.d = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1744
            this.e = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1745
            this.f = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1746
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1747
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1748
    (function (matrixproto) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1749
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1750
        matrixproto.add = function (a, b, c, d, e, f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1751
            var out = [[], [], []],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1752
                m = [[this.a, this.c, this.e], [this.b, this.d, this.f], [0, 0, 1]],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1753
                matrix = [[a, c, e], [b, d, f], [0, 0, 1]],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1754
                x, y, z, res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1755
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1756
            if (a && a instanceof Matrix) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1757
                matrix = [[a.a, a.c, a.e], [a.b, a.d, a.f], [0, 0, 1]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1758
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1759
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1760
            for (x = 0; x < 3; x++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1761
                for (y = 0; y < 3; y++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1762
                    res = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1763
                    for (z = 0; z < 3; z++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1764
                        res += m[x][z] * matrix[z][y];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1765
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1766
                    out[x][y] = res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1767
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1768
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1769
            this.a = out[0][0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1770
            this.b = out[1][0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1771
            this.c = out[0][1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1772
            this.d = out[1][1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1773
            this.e = out[0][2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1774
            this.f = out[1][2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1775
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1776
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1777
        matrixproto.invert = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1778
            var me = this,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1779
                x = me.a * me.d - me.b * me.c;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1780
            return new Matrix(me.d / x, -me.b / x, -me.c / x, me.a / x, (me.c * me.f - me.d * me.e) / x, (me.b * me.e - me.a * me.f) / x);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1781
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1782
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1783
        matrixproto.clone = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1784
            return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1785
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1786
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1787
        matrixproto.translate = function (x, y) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1788
            this.add(1, 0, 0, 1, x, y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1789
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1790
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1791
        matrixproto.scale = function (x, y, cx, cy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1792
            y == null && (y = x);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1793
            (cx || cy) && this.add(1, 0, 0, 1, cx, cy);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1794
            this.add(x, 0, 0, y, 0, 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1795
            (cx || cy) && this.add(1, 0, 0, 1, -cx, -cy);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1796
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1797
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1798
        matrixproto.rotate = function (a, x, y) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1799
            a = R.rad(a);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1800
            x = x || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1801
            y = y || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1802
            var cos = +math.cos(a).toFixed(9),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1803
                sin = +math.sin(a).toFixed(9);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1804
            this.add(cos, sin, -sin, cos, x, y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1805
            this.add(1, 0, 0, 1, -x, -y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1806
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1807
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1808
        matrixproto.x = function (x, y) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1809
            return x * this.a + y * this.c + this.e;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1810
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1811
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1812
        matrixproto.y = function (x, y) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1813
            return x * this.b + y * this.d + this.f;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1814
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1815
        matrixproto.get = function (i) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1816
            return +this[Str.fromCharCode(97 + i)].toFixed(4);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1817
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1818
        matrixproto.toString = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1819
            return R.svg ?
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1820
                "matrix(" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)].join() + ")" :
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1821
                [this.get(0), this.get(2), this.get(1), this.get(3), 0, 0].join();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1822
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1823
        matrixproto.toFilter = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1824
            return "progid:DXImageTransform.Microsoft.Matrix(M11=" + this.get(0) +
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1825
                ", M12=" + this.get(2) + ", M21=" + this.get(1) + ", M22=" + this.get(3) +
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1826
                ", Dx=" + this.get(4) + ", Dy=" + this.get(5) + ", sizingmethod='auto expand')";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1827
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1828
        matrixproto.offset = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1829
            return [this.e.toFixed(4), this.f.toFixed(4)];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1830
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1831
        function norm(a) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1832
            return a[0] * a[0] + a[1] * a[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1833
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1834
        function normalize(a) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1835
            var mag = math.sqrt(norm(a));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1836
            a[0] && (a[0] /= mag);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1837
            a[1] && (a[1] /= mag);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1838
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1839
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1840
        matrixproto.split = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1841
            var out = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1842
            // translation
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1843
            out.dx = this.e;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1844
            out.dy = this.f;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1845
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1846
            // scale and shear
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1847
            var row = [[this.a, this.c], [this.b, this.d]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1848
            out.scalex = math.sqrt(norm(row[0]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1849
            normalize(row[0]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1850
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1851
            out.shear = row[0][0] * row[1][0] + row[0][1] * row[1][1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1852
            row[1] = [row[1][0] - row[0][0] * out.shear, row[1][1] - row[0][1] * out.shear];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1853
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1854
            out.scaley = math.sqrt(norm(row[1]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1855
            normalize(row[1]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1856
            out.shear /= out.scaley;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1857
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1858
            // rotation
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1859
            var sin = -row[0][1],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1860
                cos = row[1][1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1861
            if (cos < 0) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1862
                out.rotate = R.deg(math.acos(cos));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1863
                if (sin < 0) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1864
                    out.rotate = 360 - out.rotate;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1865
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1866
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1867
                out.rotate = R.deg(math.asin(sin));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1868
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1869
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1870
            out.isSimple = !+out.shear.toFixed(9) && (out.scalex.toFixed(9) == out.scaley.toFixed(9) || !out.rotate);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1871
            out.isSuperSimple = !+out.shear.toFixed(9) && out.scalex.toFixed(9) == out.scaley.toFixed(9) && !out.rotate;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1872
            out.noRotation = !+out.shear.toFixed(9) && !out.rotate;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1873
            return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1874
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1875
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1876
        matrixproto.toTransformString = function (shorter) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1877
            var s = shorter || this[split]();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1878
            if (s.isSimple) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1879
                return "t" + [s.dx, s.dy] + "s" + [s.scalex, s.scaley, 0, 0] + "r" + [s.rotate, 0, 0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1880
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1881
                return "m" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1882
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1883
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1884
    })(Matrix.prototype);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1885
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1886
    // WebKit rendering bug workaround method
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1887
    var version = navigator.userAgent.match(/Version\/(.*?)\s/) || navigator.userAgent.match(/Chrome\/(\d+)/);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1888
    if ((navigator.vendor == "Apple Computer, Inc.") && (version && version[1] < 4 || navigator.platform.slice(0, 2) == "iP") ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1889
        (navigator.vendor == "Google Inc." && version && version[1] < 8)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1890
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1891
        paperproto.safari = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1892
            var rect = this.rect(-99, -99, this.width + 99, this.height + 99).attr({stroke: "none"});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1893
            setTimeout(function () {rect.remove();});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1894
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1895
    } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1896
        paperproto.safari = fun;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1897
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1898
 
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1899
    var preventDefault = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1900
        this.returnValue = false;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1901
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1902
    preventTouch = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1903
        return this.originalEvent.preventDefault();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1904
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1905
    stopPropagation = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1906
        this.cancelBubble = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1907
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1908
    stopTouch = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1909
        return this.originalEvent.stopPropagation();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1910
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1911
    addEvent = (function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1912
        if (g.doc.addEventListener) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1913
            return function (obj, type, fn, element) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1914
                var realName = supportsTouch && touchMap[type] ? touchMap[type] : type,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1915
                    f = function (e) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1916
                        var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1917
                            scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1918
                            x = e.clientX + scrollX,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1919
                            y = e.clientY + scrollY;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1920
                    if (supportsTouch && touchMap[has](type)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1921
                        for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1922
                            if (e.targetTouches[i].target == obj) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1923
                                var olde = e;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1924
                                e = e.targetTouches[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1925
                                e.originalEvent = olde;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1926
                                e.preventDefault = preventTouch;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1927
                                e.stopPropagation = stopTouch;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1928
                                break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1929
                            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1930
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1931
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1932
                    return fn.call(element, e, x, y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1933
                };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1934
                obj.addEventListener(realName, f, false);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1935
                return function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1936
                    obj.removeEventListener(realName, f, false);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1937
                    return true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1938
                };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1939
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1940
        } else if (g.doc.attachEvent) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1941
            return function (obj, type, fn, element) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1942
                var f = function (e) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1943
                    e = e || g.win.event;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1944
                    var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1945
                        scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1946
                        x = e.clientX + scrollX,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1947
                        y = e.clientY + scrollY;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1948
                    e.preventDefault = e.preventDefault || preventDefault;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1949
                    e.stopPropagation = e.stopPropagation || stopPropagation;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1950
                    return fn.call(element, e, x, y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1951
                };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1952
                obj.attachEvent("on" + type, f);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1953
                var detacher = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1954
                    obj.detachEvent("on" + type, f);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1955
                    return true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1956
                };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1957
                return detacher;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1958
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1959
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1960
    })(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1961
    drag = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1962
    dragMove = function (e) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1963
        var x = e.clientX,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1964
            y = e.clientY,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1965
            scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1966
            scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1967
            dragi,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1968
            j = drag.length;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1969
        while (j--) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1970
            dragi = drag[j];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1971
            if (supportsTouch) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1972
                var i = e.touches.length,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1973
                    touch;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1974
                while (i--) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1975
                    touch = e.touches[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1976
                    if (touch.identifier == dragi.el._drag.id) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1977
                        x = touch.clientX;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1978
                        y = touch.clientY;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1979
                        (e.originalEvent ? e.originalEvent : e).preventDefault();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1980
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1981
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1982
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1983
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1984
                e.preventDefault();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1985
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1986
            var node = dragi.el.node,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1987
                o,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1988
                next = node.nextSibling,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1989
                parent = node.parentNode,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1990
                display = node.style.display;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1991
            g.win.opera && parent.removeChild(node);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1992
            node.style.display = "none";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1993
            o = dragi.el.paper.getElementByPoint(x, y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1994
            node.style.display = display;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1995
            g.win.opera && (next ? parent.insertBefore(node, next) : parent.appendChild(node));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1996
            o && eve("drag.over." + dragi.el.id, dragi.el, o);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1997
            x += scrollX;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1998
            y += scrollY;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  1999
            eve("drag.move." + dragi.el.id, dragi.move_scope || dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y, e);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2000
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2001
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2002
    dragUp = function (e) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2003
        R.unmousemove(dragMove).unmouseup(dragUp);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2004
        var i = drag.length,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2005
            dragi;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2006
        while (i--) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2007
            dragi = drag[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2008
            dragi.el._drag = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2009
            eve("drag.end." + dragi.el.id, dragi.end_scope || dragi.start_scope || dragi.move_scope || dragi.el, e);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2010
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2011
        drag = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2012
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2013
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2014
    elproto = R.el = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2015
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2016
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2017
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2018
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2019
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2020
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2021
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2022
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2023
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2024
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2025
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2026
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2027
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2028
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2029
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2030
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2031
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2032
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2033
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2034
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2035
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2036
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2037
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2038
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2039
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2040
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2041
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2042
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2043
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2044
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2045
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2046
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2047
    for (var i = events.length; i--;) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2048
        (function (eventName) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2049
            R[eventName] = elproto[eventName] = function (fn, scope) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2050
                if (R.is(fn, "function")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2051
                    this.events = this.events || [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2052
                    this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || g.doc, eventName, fn, scope || this)});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2053
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2054
                return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2055
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2056
            R["un" + eventName] = elproto["un" + eventName] = function (fn) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2057
                var events = this.events,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2058
                    l = events.length;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2059
                while (l--) if (events[l].name == eventName && events[l].f == fn) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2060
                    events[l].unbind();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2061
                    events.splice(l, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2062
                    !events.length && delete this.events;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2063
                    return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2064
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2065
                return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2066
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2067
        })(events[i]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2068
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2069
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2070
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2071
    elproto.data = function (key, value) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2072
        var data = eldata[this.id] = eldata[this.id] || {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2073
        if (arguments.length == 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2074
            if (R.is(key, "object")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2075
                for (var i in key) if (key[has](i)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2076
                    this.data(i, key[i]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2077
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2078
                return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2079
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2080
            eve("data.get." + this.id, this, data[key], key);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2081
            return data[key];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2082
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2083
        data[key] = value;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2084
        eve("data.set." + this.id, this, value, key);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2085
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2086
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2087
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2088
    elproto.removeData = function (key) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2089
        if (key == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2090
            eldata[this.id] = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2091
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2092
            eldata[this.id] && delete eldata[this.id][key];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2093
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2094
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2095
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2096
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2097
    elproto.hover = function (f_in, f_out, scope_in, scope_out) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2098
        return this.mouseover(f_in, scope_in).mouseout(f_out, scope_out || scope_in);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2099
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2100
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2101
    elproto.unhover = function (f_in, f_out) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2102
        return this.unmouseover(f_in).unmouseout(f_out);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2103
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2104
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2105
    elproto.drag = function (onmove, onstart, onend, move_scope, start_scope, end_scope) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2106
        function start(e) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2107
            (e.originalEvent || e).preventDefault();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2108
            var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2109
                scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2110
            this._drag.x = e.clientX + scrollX;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2111
            this._drag.y = e.clientY + scrollY;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2112
            this._drag.id = e.identifier;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2113
            !drag.length && R.mousemove(dragMove).mouseup(dragUp);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2114
            drag.push({el: this, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2115
            onstart && eve.on("drag.start." + this.id, onstart);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2116
            onmove && eve.on("drag.move." + this.id, onmove);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2117
            onend && eve.on("drag.end." + this.id, onend);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2118
            eve("drag.start." + this.id, start_scope || move_scope || this, e.clientX + scrollX, e.clientY + scrollY, e);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2119
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2120
        this._drag = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2121
        this.mousedown(start);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2122
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2123
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2124
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2125
    elproto.onDragOver = function (f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2126
        f ? eve.on("drag.over." + this.id, f) : eve.unbind("drag.over." + this.id);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2127
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2128
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2129
    elproto.undrag = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2130
        var i = drag.length;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2131
        while (i--) if (drag[i].el == this) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2132
            R.unmousedown(drag[i].start);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2133
            drag.splice(i++, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2134
            eve.unbind("drag.*." + this.id);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2135
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2136
        !drag.length && R.unmousemove(dragMove).unmouseup(dragUp);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2137
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2138
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2139
    paperproto.circle = function (x, y, r) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2140
        var out = R._engine.circle(this, x || 0, y || 0, r || 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2141
        this.__set__ && this.__set__.push(out);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2142
        return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2143
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2144
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2145
    paperproto.rect = function (x, y, w, h, r) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2146
        var out = R._engine.rect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2147
        this.__set__ && this.__set__.push(out);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2148
        return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2149
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2150
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2151
    paperproto.ellipse = function (x, y, rx, ry) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2152
        var out = R._engine.ellipse(this, x || 0, y || 0, rx || 0, ry || 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2153
        this.__set__ && this.__set__.push(out);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2154
        return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2155
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2156
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2157
    paperproto.path = function (pathString) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2158
        pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2159
        var out = R._engine.path(R.format[apply](R, arguments), this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2160
        this.__set__ && this.__set__.push(out);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2161
        return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2162
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2163
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2164
    paperproto.image = function (src, x, y, w, h) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2165
        var out = R._engine.image(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2166
        this.__set__ && this.__set__.push(out);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2167
        return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2168
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2169
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2170
    paperproto.text = function (x, y, text) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2171
        var out = R._engine.text(this, x || 0, y || 0, Str(text));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2172
        this.__set__ && this.__set__.push(out);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2173
        return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2174
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2175
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2176
    paperproto.set = function (itemsArray) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2177
        !R.is(itemsArray, "array") && (itemsArray = Array.prototype.splice.call(arguments, 0, arguments.length));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2178
        var out = new Set(itemsArray);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2179
        this.__set__ && this.__set__.push(out);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2180
        return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2181
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2182
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2183
    paperproto.setStart = function (set) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2184
        this.__set__ = set || this.set();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2185
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2186
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2187
    paperproto.setFinish = function (set) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2188
        var out = this.__set__;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2189
        delete this.__set__;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2190
        return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2191
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2192
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2193
    paperproto.setSize = function (width, height) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2194
        return R._engine.setSize.call(this, width, height);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2195
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2196
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2197
    paperproto.setViewBox = function (x, y, w, h, fit) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2198
        return R._engine.setViewBox.call(this, x, y, w, h, fit);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2199
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2200
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2201
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2202
    paperproto.top = paperproto.bottom = null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2203
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2204
    paperproto.raphael = R;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2205
    var getOffset = function (elem) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2206
        var box = elem.getBoundingClientRect(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2207
            doc = elem.ownerDocument,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2208
            body = doc.body,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2209
            docElem = doc.documentElement,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2210
            clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2211
            top  = box.top  + (g.win.pageYOffset || docElem.scrollTop || body.scrollTop ) - clientTop,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2212
            left = box.left + (g.win.pageXOffset || docElem.scrollLeft || body.scrollLeft) - clientLeft;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2213
        return {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2214
            y: top,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2215
            x: left
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2216
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2217
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2218
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2219
    paperproto.getElementByPoint = function (x, y) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2220
        var paper = this,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2221
            svg = paper.canvas,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2222
            target = g.doc.elementFromPoint(x, y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2223
        if (g.win.opera && target.tagName == "svg") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2224
            var so = getOffset(svg),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2225
                sr = svg.createSVGRect();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2226
            sr.x = x - so.x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2227
            sr.y = y - so.y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2228
            sr.width = sr.height = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2229
            var hits = svg.getIntersectionList(sr, null);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2230
            if (hits.length) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2231
                target = hits[hits.length - 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2232
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2233
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2234
        if (!target) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2235
            return null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2236
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2237
        while (target.parentNode && target != svg.parentNode && !target.raphael) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2238
            target = target.parentNode;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2239
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2240
        target == paper.canvas.parentNode && (target = svg);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2241
        target = target && target.raphael ? paper.getById(target.raphaelid) : null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2242
        return target;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2243
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2244
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2245
    paperproto.getById = function (id) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2246
        var bot = this.bottom;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2247
        while (bot) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2248
            if (bot.id == id) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2249
                return bot;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2250
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2251
            bot = bot.next;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2252
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2253
        return null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2254
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2255
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2256
    paperproto.forEach = function (callback, thisArg) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2257
        var bot = this.bottom;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2258
        while (bot) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2259
            if (callback.call(thisArg, bot) === false) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2260
                return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2261
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2262
            bot = bot.next;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2263
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2264
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2265
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2266
    function x_y() {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2267
        return this.x + S + this.y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2268
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2269
    function x_y_w_h() {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2270
        return this.x + S + this.y + S + this.width + " \xd7 " + this.height;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2271
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2272
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2273
    elproto.getBBox = function (isWithoutTransform) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2274
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2275
            return {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2276
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2277
        var _ = this._;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2278
        if (isWithoutTransform) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2279
            if (_.dirty || !_.bboxwt) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2280
                this.realPath = getPath[this.type](this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2281
                _.bboxwt = pathDimensions(this.realPath);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2282
                _.bboxwt.toString = x_y_w_h;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2283
                _.dirty = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2284
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2285
            return _.bboxwt;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2286
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2287
        if (_.dirty || _.dirtyT || !_.bbox) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2288
            if (_.dirty || !this.realPath) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2289
                _.bboxwt = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2290
                this.realPath = getPath[this.type](this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2291
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2292
            _.bbox = pathDimensions(mapPath(this.realPath, this.matrix));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2293
            _.bbox.toString = x_y_w_h;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2294
            _.dirty = _.dirtyT = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2295
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2296
        return _.bbox;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2297
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2298
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2299
    elproto.clone = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2300
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2301
            return null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2302
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2303
        var out = this.paper[this.type]().attr(this.attr());
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2304
        this.__set__ && this.__set__.push(out);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2305
        return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2306
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2307
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2308
    elproto.glow = function (glow) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2309
        if (this.type == "text") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2310
            return null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2311
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2312
        glow = glow || {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2313
        var s = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2314
            width: (glow.width || 10) + (+this.attr("stroke-width") || 1),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2315
            fill: glow.fill || false,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2316
            opacity: glow.opacity || .5,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2317
            offsetx: glow.offsetx || 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2318
            offsety: glow.offsety || 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2319
            color: glow.color || "#000"
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2320
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2321
            c = s.width / 2,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2322
            r = this.paper,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2323
            out = r.set(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2324
            path = this.realPath || getPath[this.type](this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2325
        path = this.matrix ? mapPath(path, this.matrix) : path;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2326
        for (var i = 1; i < c + 1; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2327
            out.push(r.path(path).attr({
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2328
                stroke: s.color,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2329
                fill: s.fill ? s.color : "none",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2330
                "stroke-linejoin": "round",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2331
                "stroke-linecap": "round",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2332
                "stroke-width": +(s.width / c * i).toFixed(3),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2333
                opacity: +(s.opacity / c).toFixed(3)
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2334
            }));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2335
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2336
        return out.insertBefore(this).translate(s.offsetx, s.offsety);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2337
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2338
    var curveslengths = {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2339
    getPointAtSegmentLength = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2340
        var len = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2341
            precision = 100,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2342
            name = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y].join(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2343
            cache = curveslengths[name],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2344
            old, dot;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2345
        !cache && (curveslengths[name] = cache = {data: []});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2346
        cache.timer && clearTimeout(cache.timer);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2347
        cache.timer = setTimeout(function () {delete curveslengths[name];}, 2e3);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2348
        if (length != null && !cache.precision) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2349
            var total = getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2350
            cache.precision = ~~total * 10;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2351
            cache.data = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2352
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2353
        precision = cache.precision || precision;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2354
        for (var i = 0; i < precision + 1; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2355
            if (cache.data[i * precision]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2356
                dot = cache.data[i * precision];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2357
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2358
                dot = R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i / precision);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2359
                cache.data[i * precision] = dot;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2360
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2361
            i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2362
            if (length != null && len >= length) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2363
                return dot;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2364
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2365
            old = dot;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2366
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2367
        if (length == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2368
            return len;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2369
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2370
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2371
    getLengthFactory = function (istotal, subpath) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2372
        return function (path, length, onlystart) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2373
            path = path2curve(path);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2374
            var x, y, p, l, sp = "", subpaths = {}, point,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2375
                len = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2376
            for (var i = 0, ii = path.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2377
                p = path[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2378
                if (p[0] == "M") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2379
                    x = +p[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2380
                    y = +p[2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2381
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2382
                    l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2383
                    if (len + l > length) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2384
                        if (subpath && !subpaths.start) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2385
                            point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2386
                            sp += ["C" + point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2387
                            if (onlystart) {return sp;}
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2388
                            subpaths.start = sp;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2389
                            sp = ["M" + point.x, point.y + "C" + point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]].join();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2390
                            len += l;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2391
                            x = +p[5];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2392
                            y = +p[6];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2393
                            continue;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2394
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2395
                        if (!istotal && !subpath) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2396
                            point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2397
                            return {x: point.x, y: point.y, alpha: point.alpha};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2398
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2399
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2400
                    len += l;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2401
                    x = +p[5];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2402
                    y = +p[6];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2403
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2404
                sp += p.shift() + p;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2405
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2406
            subpaths.end = sp;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2407
            point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[0], p[1], p[2], p[3], p[4], p[5], 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2408
            point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2409
            return point;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2410
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2411
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2412
    var getTotalLength = getLengthFactory(1),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2413
        getPointAtLength = getLengthFactory(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2414
        getSubpathsAtLength = getLengthFactory(0, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2415
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2416
    R.getTotalLength = getTotalLength;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2417
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2418
    R.getPointAtLength = getPointAtLength;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2419
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2420
    R.getSubpath = function (path, from, to) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2421
        if (this.getTotalLength(path) - to < 1e-6) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2422
            return getSubpathsAtLength(path, from).end;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2423
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2424
        var a = getSubpathsAtLength(path, to, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2425
        return from ? getSubpathsAtLength(a, from).end : a;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2426
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2427
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2428
    elproto.getTotalLength = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2429
        if (this.type != "path") {return;}
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2430
        if (this.node.getTotalLength) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2431
            return this.node.getTotalLength();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2432
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2433
        return getTotalLength(this.attrs.path);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2434
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2435
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2436
    elproto.getPointAtLength = function (length) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2437
        if (this.type != "path") {return;}
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2438
        return getPointAtLength(this.attrs.path, length);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2439
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2440
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2441
    elproto.getSubpath = function (from, to) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2442
        if (this.type != "path") {return;}
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2443
        return R.getSubpath(this.attrs.path, from, to);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2444
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2445
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2446
    var ef = R.easing_formulas = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2447
        linear: function (n) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2448
            return n;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2449
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2450
        "<": function (n) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2451
            return pow(n, 1.7);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2452
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2453
        ">": function (n) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2454
            return pow(n, .48);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2455
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2456
        "<>": function (n) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2457
            var q = .48 - n / 1.04,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2458
                Q = math.sqrt(.1734 + q * q),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2459
                x = Q - q,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2460
                X = pow(abs(x), 1 / 3) * (x < 0 ? -1 : 1),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2461
                y = -Q - q,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2462
                Y = pow(abs(y), 1 / 3) * (y < 0 ? -1 : 1),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2463
                t = X + Y + .5;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2464
            return (1 - t) * 3 * t * t + t * t * t;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2465
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2466
        backIn: function (n) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2467
            var s = 1.70158;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2468
            return n * n * ((s + 1) * n - s);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2469
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2470
        backOut: function (n) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2471
            n = n - 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2472
            var s = 1.70158;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2473
            return n * n * ((s + 1) * n + s) + 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2474
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2475
        elastic: function (n) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2476
            if (n == !!n) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2477
                return n;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2478
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2479
            return pow(2, -10 * n) * math.sin((n - .075) * (2 * PI) / .3) + 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2480
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2481
        bounce: function (n) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2482
            var s = 7.5625,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2483
                p = 2.75,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2484
                l;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2485
            if (n < (1 / p)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2486
                l = s * n * n;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2487
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2488
                if (n < (2 / p)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2489
                    n -= (1.5 / p);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2490
                    l = s * n * n + .75;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2491
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2492
                    if (n < (2.5 / p)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2493
                        n -= (2.25 / p);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2494
                        l = s * n * n + .9375;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2495
                    } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2496
                        n -= (2.625 / p);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2497
                        l = s * n * n + .984375;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2498
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2499
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2500
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2501
            return l;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2502
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2503
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2504
    ef.easeIn = ef["ease-in"] = ef["<"];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2505
    ef.easeOut = ef["ease-out"] = ef[">"];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2506
    ef.easeInOut = ef["ease-in-out"] = ef["<>"];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2507
    ef["back-in"] = ef.backIn;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2508
    ef["back-out"] = ef.backOut;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2509
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2510
    var animationElements = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2511
        requestAnimFrame = window.requestAnimationFrame       ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2512
                           window.webkitRequestAnimationFrame ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2513
                           window.mozRequestAnimationFrame    ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2514
                           window.oRequestAnimationFrame      ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2515
                           window.msRequestAnimationFrame     ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2516
                           function (callback) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2517
                               setTimeout(callback, 16);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2518
                           },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2519
        animation = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2520
            var Now = +new Date,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2521
                l = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2522
            for (; l < animationElements.length; l++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2523
                var e = animationElements[l];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2524
                if (e.el.removed || e.paused) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2525
                    continue;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2526
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2527
                var time = Now - e.start,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2528
                    ms = e.ms,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2529
                    easing = e.easing,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2530
                    from = e.from,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2531
                    diff = e.diff,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2532
                    to = e.to,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2533
                    t = e.t,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2534
                    that = e.el,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2535
                    set = {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2536
                    now,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2537
                    init = {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2538
                    key;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2539
                if (e.initstatus) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2540
                    time = (e.initstatus * e.anim.top - e.prev) / (e.percent - e.prev) * ms;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2541
                    e.status = e.initstatus;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2542
                    delete e.initstatus;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2543
                    e.stop && animationElements.splice(l--, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2544
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2545
                    e.status = (e.prev + (e.percent - e.prev) * (time / ms)) / e.anim.top;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2546
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2547
                if (time < 0) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2548
                    continue;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2549
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2550
                if (time < ms) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2551
                    var pos = easing(time / ms);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2552
                    for (var attr in from) if (from[has](attr)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2553
                        switch (availableAnimAttrs[attr]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2554
                            case nu:
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2555
                                now = +from[attr] + pos * ms * diff[attr];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2556
                                break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2557
                            case "colour":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2558
                                now = "rgb(" + [
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2559
                                    upto255(round(from[attr].r + pos * ms * diff[attr].r)),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2560
                                    upto255(round(from[attr].g + pos * ms * diff[attr].g)),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2561
                                    upto255(round(from[attr].b + pos * ms * diff[attr].b))
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2562
                                ].join(",") + ")";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2563
                                break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2564
                            case "path":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2565
                                now = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2566
                                for (var i = 0, ii = from[attr].length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2567
                                    now[i] = [from[attr][i][0]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2568
                                    for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2569
                                        now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2570
                                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2571
                                    now[i] = now[i].join(S);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2572
                                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2573
                                now = now.join(S);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2574
                                break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2575
                            case "transform":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2576
                                if (diff[attr].real) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2577
                                    now = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2578
                                    for (i = 0, ii = from[attr].length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2579
                                        now[i] = [from[attr][i][0]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2580
                                        for (j = 1, jj = from[attr][i].length; j < jj; j++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2581
                                            now[i][j] = from[attr][i][j] + pos * ms * diff[attr][i][j];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2582
                                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2583
                                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2584
                                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2585
                                    var get = function (i) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2586
                                        return +from[attr][i] + pos * ms * diff[attr][i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2587
                                    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2588
                                    // now = [["r", get(2), 0, 0], ["t", get(3), get(4)], ["s", get(0), get(1), 0, 0]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2589
                                    now = [["m", get(0), get(1), get(2), get(3), get(4), get(5)]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2590
                                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2591
                                break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2592
                            case "csv":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2593
                                if (attr == "clip-rect") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2594
                                    now = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2595
                                    i = 4;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2596
                                    while (i--) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2597
                                        now[i] = +from[attr][i] + pos * ms * diff[attr][i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2598
                                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2599
                                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2600
                                break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2601
                            default:
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2602
                                var from2 = [][concat](from[attr]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2603
                                now = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2604
                                i = that.paper.customAttributes[attr].length;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2605
                                while (i--) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2606
                                    now[i] = +from2[i] + pos * ms * diff[attr][i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2607
                                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2608
                                break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2609
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2610
                        set[attr] = now;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2611
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2612
                    that.attr(set);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2613
                    (function (id, that, anim) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2614
                        setTimeout(function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2615
                            eve("anim.frame." + id, that, anim);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2616
                        });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2617
                    })(that.id, that, e.anim);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2618
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2619
                    (function(f, el, a) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2620
                        setTimeout(function() {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2621
                            eve("anim.frame." + el.id, el, a);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2622
                            eve("anim.finish." + el.id, el, a);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2623
                            R.is(f, "function") && f.call(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2624
                        });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2625
                    })(e.callback, that, e.anim);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2626
                    that.attr(to);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2627
                    animationElements.splice(l--, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2628
                    if (e.repeat > 1 && !e.next) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2629
                        for (key in to) if (to[has](key)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2630
                            init[key] = e.totalOrigin[key];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2631
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2632
                        e.el.attr(init);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2633
                        runAnimation(e.anim, e.el, e.anim.percents[0], null, e.totalOrigin, e.repeat - 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2634
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2635
                    if (e.next && !e.stop) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2636
                        runAnimation(e.anim, e.el, e.next, null, e.totalOrigin, e.repeat);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2637
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2638
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2639
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2640
            R.svg && that && that.paper && that.paper.safari();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2641
            animationElements.length && requestAnimFrame(animation);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2642
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2643
        upto255 = function (color) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2644
            return color > 255 ? 255 : color < 0 ? 0 : color;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2645
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2646
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2647
    elproto.animateWith = function (element, anim, params, ms, easing, callback) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2648
        var a = params ? R.animation(params, ms, easing, callback) : anim;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2649
            status = element.status(anim);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2650
        return this.animate(a).status(a, status * anim.ms / a.ms);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2651
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2652
    function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2653
        var cx = 3 * p1x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2654
            bx = 3 * (p2x - p1x) - cx,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2655
            ax = 1 - cx - bx,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2656
            cy = 3 * p1y,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2657
            by = 3 * (p2y - p1y) - cy,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2658
            ay = 1 - cy - by;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2659
        function sampleCurveX(t) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2660
            return ((ax * t + bx) * t + cx) * t;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2661
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2662
        function solve(x, epsilon) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2663
            var t = solveCurveX(x, epsilon);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2664
            return ((ay * t + by) * t + cy) * t;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2665
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2666
        function solveCurveX(x, epsilon) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2667
            var t0, t1, t2, x2, d2, i;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2668
            for(t2 = x, i = 0; i < 8; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2669
                x2 = sampleCurveX(t2) - x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2670
                if (abs(x2) < epsilon) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2671
                    return t2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2672
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2673
                d2 = (3 * ax * t2 + 2 * bx) * t2 + cx;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2674
                if (abs(d2) < 1e-6) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2675
                    break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2676
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2677
                t2 = t2 - x2 / d2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2678
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2679
            t0 = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2680
            t1 = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2681
            t2 = x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2682
            if (t2 < t0) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2683
                return t0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2684
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2685
            if (t2 > t1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2686
                return t1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2687
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2688
            while (t0 < t1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2689
                x2 = sampleCurveX(t2);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2690
                if (abs(x2 - x) < epsilon) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2691
                    return t2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2692
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2693
                if (x > x2) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2694
                    t0 = t2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2695
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2696
                    t1 = t2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2697
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2698
                t2 = (t1 - t0) / 2 + t0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2699
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2700
            return t2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2701
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2702
        return solve(t, 1 / (200 * duration));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2703
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2704
    elproto.onAnimation = function (f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2705
        f ? eve.on("anim.frame." + this.id, f) : eve.unbind("anim.frame." + this.id);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2706
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2707
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2708
    function Animation(anim, ms) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2709
        var percents = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2710
            newAnim = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2711
        this.ms = ms;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2712
        this.times = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2713
        if (anim) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2714
            for (var attr in anim) if (anim[has](attr)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2715
                newAnim[toFloat(attr)] = anim[attr];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2716
                percents.push(toFloat(attr));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2717
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2718
            percents.sort(sortByNumber);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2719
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2720
        this.anim = newAnim;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2721
        this.top = percents[percents.length - 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2722
        this.percents = percents;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2723
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2724
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2725
    Animation.prototype.delay = function (delay) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2726
        var a = new Animation(this.anim, this.ms);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2727
        a.times = this.times;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2728
        a.del = +delay || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2729
        return a;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2730
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2731
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2732
    Animation.prototype.repeat = function (times) { 
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2733
        var a = new Animation(this.anim, this.ms);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2734
        a.del = this.del;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2735
        a.times = math.floor(mmax(times, 0)) || 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2736
        return a;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2737
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2738
    function runAnimation(anim, element, percent, status, totalOrigin, times) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2739
        percent = toFloat(percent);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2740
        var params,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2741
            isInAnim,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2742
            isInAnimSet,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2743
            percents = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2744
            next,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2745
            prev,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2746
            timestamp,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2747
            ms = anim.ms,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2748
            from = {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2749
            to = {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2750
            diff = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2751
        if (status) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2752
            for (i = 0, ii = animationElements.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2753
                var e = animationElements[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2754
                if (e.el.id == element.id && e.anim == anim) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2755
                    if (e.percent != percent) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2756
                        animationElements.splice(i, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2757
                        isInAnimSet = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2758
                    } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2759
                        isInAnim = e;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2760
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2761
                    element.attr(e.totalOrigin);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2762
                    break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2763
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2764
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2765
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2766
            status = +to; // NaN
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2767
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2768
        for (var i = 0, ii = anim.percents.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2769
            if (anim.percents[i] == percent || anim.percents[i] > status * anim.top) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2770
                percent = anim.percents[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2771
                prev = anim.percents[i - 1] || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2772
                ms = ms / anim.top * (percent - prev);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2773
                next = anim.percents[i + 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2774
                params = anim.anim[percent];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2775
                break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2776
            } else if (status) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2777
                element.attr(anim.anim[anim.percents[i]]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2778
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2779
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2780
        if (!params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2781
            return;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2782
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2783
        if (!isInAnim) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2784
            for (attr in params) if (params[has](attr)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2785
                if (availableAnimAttrs[has](attr) || element.paper.customAttributes[has](attr)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2786
                    from[attr] = element.attr(attr);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2787
                    (from[attr] == null) && (from[attr] = availableAttrs[attr]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2788
                    to[attr] = params[attr];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2789
                    switch (availableAnimAttrs[attr]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2790
                        case nu:
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2791
                            diff[attr] = (to[attr] - from[attr]) / ms;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2792
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2793
                        case "colour":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2794
                            from[attr] = R.getRGB(from[attr]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2795
                            var toColour = R.getRGB(to[attr]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2796
                            diff[attr] = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2797
                                r: (toColour.r - from[attr].r) / ms,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2798
                                g: (toColour.g - from[attr].g) / ms,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2799
                                b: (toColour.b - from[attr].b) / ms
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2800
                            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2801
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2802
                        case "path":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2803
                            var pathes = path2curve(from[attr], to[attr]),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2804
                                toPath = pathes[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2805
                            from[attr] = pathes[0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2806
                            diff[attr] = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2807
                            for (i = 0, ii = from[attr].length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2808
                                diff[attr][i] = [0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2809
                                for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2810
                                    diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2811
                                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2812
                            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2813
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2814
                        case "transform":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2815
                            var _ = element._,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2816
                                eq = equaliseTransform(_[attr], to[attr]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2817
                            if (eq) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2818
                                from[attr] = eq.from;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2819
                                to[attr] = eq.to;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2820
                                diff[attr] = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2821
                                diff[attr].real = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2822
                                for (i = 0, ii = from[attr].length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2823
                                    diff[attr][i] = [from[attr][i][0]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2824
                                    for (j = 1, jj = from[attr][i].length; j < jj; j++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2825
                                        diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2826
                                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2827
                                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2828
                            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2829
                                var m = (element.matrix || new Matrix),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2830
                                    to2 = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2831
                                        _: {transform: _.transform},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2832
                                        getBBox: function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2833
                                            return element.getBBox(1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2834
                                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2835
                                    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2836
                                from[attr] = [
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2837
                                    m.a,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2838
                                    m.b,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2839
                                    m.c,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2840
                                    m.d,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2841
                                    m.e,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2842
                                    m.f
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2843
                                ];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2844
                                extractTransform(to2, to[attr]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2845
                                to[attr] = to2._.transform;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2846
                                diff[attr] = [
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2847
                                    (to2.matrix.a - m.a) / ms,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2848
                                    (to2.matrix.b - m.b) / ms,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2849
                                    (to2.matrix.c - m.c) / ms,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2850
                                    (to2.matrix.d - m.d) / ms,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2851
                                    (to2.matrix.e - m.e) / ms,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2852
                                    (to2.matrix.e - m.f) / ms
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2853
                                ];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2854
                                // from[attr] = [_.sx, _.sy, _.deg, _.dx, _.dy];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2855
                                // var to2 = {_:{}, getBBox: function () { return element.getBBox(); }};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2856
                                // extractTransform(to2, to[attr]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2857
                                // diff[attr] = [
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2858
                                //     (to2._.sx - _.sx) / ms,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2859
                                //     (to2._.sy - _.sy) / ms,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2860
                                //     (to2._.deg - _.deg) / ms,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2861
                                //     (to2._.dx - _.dx) / ms,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2862
                                //     (to2._.dy - _.dy) / ms
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2863
                                // ];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2864
                            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2865
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2866
                        case "csv":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2867
                            var values = Str(params[attr])[split](separator),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2868
                                from2 = Str(from[attr])[split](separator);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2869
                            if (attr == "clip-rect") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2870
                                from[attr] = from2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2871
                                diff[attr] = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2872
                                i = from2.length;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2873
                                while (i--) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2874
                                    diff[attr][i] = (values[i] - from[attr][i]) / ms;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2875
                                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2876
                            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2877
                            to[attr] = values;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2878
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2879
                        default:
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2880
                            values = [][concat](params[attr]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2881
                            from2 = [][concat](from[attr]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2882
                            diff[attr] = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2883
                            i = element.paper.customAttributes[attr].length;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2884
                            while (i--) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2885
                                diff[attr][i] = ((values[i] || 0) - (from2[i] || 0)) / ms;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2886
                            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2887
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2888
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2889
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2890
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2891
            var easing = params.easing,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2892
                easyeasy = R.easing_formulas[easing];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2893
            if (!easyeasy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2894
                easyeasy = Str(easing).match(bezierrg);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2895
                if (easyeasy && easyeasy.length == 5) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2896
                    var curve = easyeasy;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2897
                    easyeasy = function (t) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2898
                        return CubicBezierAtTime(t, +curve[1], +curve[2], +curve[3], +curve[4], ms);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2899
                    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2900
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2901
                    easyeasy = pipe;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2902
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2903
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2904
            timestamp = params.start || anim.start || +new Date;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2905
            e = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2906
                anim: anim,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2907
                percent: percent,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2908
                timestamp: timestamp,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2909
                start: timestamp + (anim.del || 0),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2910
                status: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2911
                initstatus: status || 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2912
                stop: false,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2913
                ms: ms,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2914
                easing: easyeasy,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2915
                from: from,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2916
                diff: diff,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2917
                to: to,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2918
                el: element,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2919
                callback: params.callback,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2920
                prev: prev,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2921
                next: next,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2922
                repeat: times || anim.times,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2923
                origin: element.attr(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2924
                totalOrigin: totalOrigin
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2925
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2926
            animationElements.push(e);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2927
            if (status && !isInAnim && !isInAnimSet) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2928
                e.stop = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2929
                e.start = new Date - ms * status;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2930
                if (animationElements.length == 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2931
                    return animation();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2932
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2933
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2934
            if (isInAnimSet) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2935
                e.start = new Date - e.ms * status;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2936
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2937
            animationElements.length == 1 && requestAnimFrame(animation);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2938
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2939
            isInAnim.initstatus = status;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2940
            isInAnim.start = new Date - isInAnim.ms * status;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2941
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2942
        eve("anim.start." + element.id, element, anim);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2943
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2944
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2945
    R.animation = function (params, ms, easing, callback) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2946
        if (params instanceof Animation) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2947
            return params;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2948
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2949
        if (R.is(easing, "function") || !easing) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2950
            callback = callback || easing || null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2951
            easing = null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2952
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2953
        params = Object(params);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2954
        ms = +ms || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2955
        var p = {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2956
            json,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2957
            attr;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2958
        for (attr in params) if (params[has](attr) && toFloat(attr) != attr && toFloat(attr) + "%" != attr) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2959
            json = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2960
            p[attr] = params[attr];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2961
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2962
        if (!json) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2963
            return new Animation(params, ms);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2964
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2965
            easing && (p.easing = easing);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2966
            callback && (p.callback = callback);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2967
            return new Animation({100: p}, ms);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2968
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2969
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2970
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2971
    elproto.animate = function (params, ms, easing, callback) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2972
        var element = this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2973
        if (element.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2974
            callback && callback.call(element);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2975
            return element;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2976
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2977
        var anim = params instanceof Animation ? params : R.animation(params, ms, easing, callback);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2978
        runAnimation(anim, element, anim.percents[0], null, element.attr());
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2979
        return element;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2980
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2981
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2982
    elproto.setTime = function (anim, value) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2983
        if (anim && value != null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2984
            this.status(anim, mmin(value, anim.ms) / anim.ms);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2985
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2986
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2987
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2988
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2989
    elproto.status = function (anim, value) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2990
        var out = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2991
            i = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2992
            len,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2993
            e;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2994
        if (value != null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2995
            runAnimation(anim, this, -1, mmin(value, 1));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2996
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2997
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2998
            len = animationElements.length;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  2999
            for (; i < len; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3000
                e = animationElements[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3001
                if (e.el.id == this.id && (!anim || e.anim == anim)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3002
                    if (anim) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3003
                        return e.status;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3004
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3005
                    out.push({
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3006
                        anim: e.anim,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3007
                        status: e.status
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3008
                    });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3009
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3010
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3011
            if (anim) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3012
                return 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3013
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3014
            return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3015
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3016
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3017
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3018
    elproto.pause = function (anim) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3019
        for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3020
            if (eve("anim.pause." + this.id, this, animationElements[i].anim) !== false) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3021
                animationElements[i].paused = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3022
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3023
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3024
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3025
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3026
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3027
    elproto.resume = function (anim) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3028
        for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3029
            var e = animationElements[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3030
            if (eve("anim.resume." + this.id, this, e.anim) !== false) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3031
                delete e.paused;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3032
                this.status(e.anim, e.status);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3033
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3034
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3035
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3036
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3037
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3038
    elproto.stop = function (anim) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3039
        for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3040
            if (eve("anim.stop." + this.id, this, animationElements[i].anim) !== false) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3041
                animationElements.splice(i--, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3042
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3043
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3044
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3045
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3046
    elproto.toString = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3047
        return "Rapha\xebl\u2019s object";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3048
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3049
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3050
    // Set
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3051
    var Set = function (items) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3052
        this.items = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3053
        this.length = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3054
        this.type = "set";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3055
        if (items) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3056
            for (var i = 0, ii = items.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3057
                if (items[i] && (items[i].constructor == elproto.constructor || items[i].constructor == Set)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3058
                    this[this.items.length] = this.items[this.items.length] = items[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3059
                    this.length++;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3060
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3061
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3062
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3063
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3064
    setproto = Set.prototype;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3065
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3066
    setproto.push = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3067
        var item,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3068
            len;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3069
        for (var i = 0, ii = arguments.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3070
            item = arguments[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3071
            if (item && (item.constructor == elproto.constructor || item.constructor == Set)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3072
                len = this.items.length;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3073
                this[len] = this.items[len] = item;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3074
                this.length++;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3075
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3076
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3077
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3078
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3079
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3080
    setproto.pop = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3081
        this.length && delete this[this.length--];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3082
        return this.items.pop();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3083
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3084
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3085
    setproto.forEach = function (callback, thisArg) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3086
        for (var i = 0, ii = this.items.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3087
            if (callback.call(thisArg, this.items[i], i) === false) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3088
                return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3089
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3090
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3091
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3092
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3093
    for (var method in elproto) if (elproto[has](method)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3094
        setproto[method] = (function (methodname) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3095
            return function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3096
                var arg = arguments;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3097
                return this.forEach(function (el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3098
                    el[methodname][apply](el, arg);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3099
                });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3100
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3101
        })(method);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3102
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3103
    setproto.attr = function (name, value) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3104
        if (name && R.is(name, array) && R.is(name[0], "object")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3105
            for (var j = 0, jj = name.length; j < jj; j++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3106
                this.items[j].attr(name[j]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3107
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3108
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3109
            for (var i = 0, ii = this.items.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3110
                this.items[i].attr(name, value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3111
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3112
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3113
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3114
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3115
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3116
    setproto.clear = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3117
        while (this.length) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3118
            this.pop();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3119
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3120
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3121
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3122
    setproto.splice = function (index, count, insertion) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3123
        index = index < 0 ? mmax(this.length + index, 0) : index;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3124
        count = mmax(0, mmin(this.length - index, count));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3125
        var tail = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3126
            todel = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3127
            args = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3128
            i;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3129
        for (i = 2; i < arguments.length; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3130
            args.push(arguments[i]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3131
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3132
        for (i = 0; i < count; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3133
            todel.push(this[index + i]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3134
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3135
        for (; i < this.length - index; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3136
            tail.push(this[index + i]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3137
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3138
        var arglen = args.length;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3139
        for (i = 0; i < arglen + tail.length; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3140
            this.items[index + i] = this[index + i] = i < arglen ? args[i] : tail[i - arglen];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3141
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3142
        i = this.items.length = this.length -= count - arglen;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3143
        while (this[i]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3144
            delete this[i++];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3145
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3146
        return new Set(todel);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3147
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3148
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3149
    setproto.exclude = function (el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3150
        for (var i = 0, ii = this.length; i < ii; i++) if (this[i] == el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3151
            this.splice(i, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3152
            return true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3153
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3154
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3155
    setproto.animate = function (params, ms, easing, callback) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3156
        (R.is(easing, "function") || !easing) && (callback = easing || null);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3157
        var len = this.items.length,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3158
            i = len,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3159
            item,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3160
            set = this,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3161
            collector;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3162
        if (!len) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3163
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3164
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3165
        callback && (collector = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3166
            !--len && callback.call(set);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3167
        });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3168
        easing = R.is(easing, string) ? easing : collector;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3169
        var anim = R.animation(params, ms, easing, collector);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3170
        item = this.items[--i].animate(anim);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3171
        while (i--) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3172
            this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, anim);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3173
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3174
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3175
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3176
    setproto.insertAfter = function (el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3177
        var i = this.items.length;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3178
        while (i--) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3179
            this.items[i].insertAfter(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3180
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3181
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3182
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3183
    setproto.getBBox = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3184
        var x = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3185
            y = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3186
            w = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3187
            h = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3188
        for (var i = this.items.length; i--;) if (!this.items[i].removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3189
            var box = this.items[i].getBBox();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3190
            x.push(box.x);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3191
            y.push(box.y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3192
            w.push(box.x + box.width);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3193
            h.push(box.y + box.height);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3194
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3195
        x = mmin[apply](0, x);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3196
        y = mmin[apply](0, y);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3197
        return {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3198
            x: x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3199
            y: y,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3200
            width: mmax[apply](0, w) - x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3201
            height: mmax[apply](0, h) - y
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3202
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3203
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3204
    setproto.clone = function (s) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3205
        s = new Set;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3206
        for (var i = 0, ii = this.items.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3207
            s.push(this.items[i].clone());
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3208
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3209
        return s;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3210
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3211
    setproto.toString = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3212
        return "Rapha\xebl\u2018s set";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3213
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3214
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3215
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3216
    R.registerFont = function (font) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3217
        if (!font.face) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3218
            return font;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3219
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3220
        this.fonts = this.fonts || {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3221
        var fontcopy = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3222
                w: font.w,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3223
                face: {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3224
                glyphs: {}
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3225
            },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3226
            family = font.face["font-family"];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3227
        for (var prop in font.face) if (font.face[has](prop)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3228
            fontcopy.face[prop] = font.face[prop];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3229
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3230
        if (this.fonts[family]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3231
            this.fonts[family].push(fontcopy);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3232
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3233
            this.fonts[family] = [fontcopy];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3234
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3235
        if (!font.svg) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3236
            fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3237
            for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3238
                var path = font.glyphs[glyph];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3239
                fontcopy.glyphs[glyph] = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3240
                    w: path.w,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3241
                    k: {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3242
                    d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3243
                            return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3244
                        }) + "z"
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3245
                };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3246
                if (path.k) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3247
                    for (var k in path.k) if (path[has](k)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3248
                        fontcopy.glyphs[glyph].k[k] = path.k[k];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3249
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3250
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3251
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3252
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3253
        return font;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3254
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3255
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3256
    paperproto.getFont = function (family, weight, style, stretch) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3257
        stretch = stretch || "normal";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3258
        style = style || "normal";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3259
        weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3260
        if (!R.fonts) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3261
            return;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3262
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3263
        var font = R.fonts[family];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3264
        if (!font) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3265
            var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3266
            for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3267
                if (name.test(fontName)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3268
                    font = R.fonts[fontName];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3269
                    break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3270
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3271
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3272
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3273
        var thefont;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3274
        if (font) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3275
            for (var i = 0, ii = font.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3276
                thefont = font[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3277
                if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3278
                    break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3279
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3280
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3281
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3282
        return thefont;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3283
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3284
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3285
    paperproto.print = function (x, y, string, font, size, origin, letter_spacing) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3286
        origin = origin || "middle"; // baseline|middle
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3287
        letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3288
        var out = this.set(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3289
            letters = Str(string)[split](E),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3290
            shift = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3291
            path = E,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3292
            scale;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3293
        R.is(font, string) && (font = this.getFont(font));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3294
        if (font) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3295
            scale = (size || 16) / font.face["units-per-em"];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3296
            var bb = font.face.bbox[split](separator),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3297
                top = +bb[0],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3298
                height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3299
            for (var i = 0, ii = letters.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3300
                var prev = i && font.glyphs[letters[i - 1]] || {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3301
                    curr = font.glyphs[letters[i]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3302
                shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) + (font.w * letter_spacing) : 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3303
                curr && curr.d && out.push(this.path(curr.d).attr({
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3304
                    fill: "#000",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3305
                    stroke: "none",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3306
                    transform: [["t", shift * scale, 0]]
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3307
                }));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3308
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3309
            out.transform(["...s", scale, scale, top, height, "t", (x - top) / scale, (y - height) / scale]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3310
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3311
        return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3312
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3313
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3314
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3315
    R.format = function (token, params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3316
        var args = R.is(params, array) ? [0][concat](params) : arguments;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3317
        token && R.is(token, string) && args.length - 1 && (token = token.replace(formatrg, function (str, i) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3318
            return args[++i] == null ? E : args[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3319
        }));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3320
        return token || E;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3321
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3322
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3323
    R.fullfill = (function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3324
        var tokenRegex = /\{([^\}]+)\}/g,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3325
            objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g, // matches .xxxxx or ["xxxxx"] to run over object properties
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3326
            replacer = function (all, key, obj) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3327
                var res = obj;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3328
                key.replace(objNotationRegex, function (all, name, quote, quotedName, isFunc) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3329
                    name = name || quotedName;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3330
                    if (res) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3331
                        if (name in res) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3332
                            res = res[name];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3333
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3334
                        typeof res == "function" && isFunc && (res = res());
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3335
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3336
                });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3337
                res = (res == null || res == obj ? all : res) + "";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3338
                return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3339
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3340
        return function (str, obj) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3341
            return String(str).replace(tokenRegex, function (all, key) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3342
                return replacer(all, key, obj);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3343
            });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3344
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3345
    })();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3346
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3347
    R.ninja = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3348
        oldRaphael.was ? (g.win.Raphael = oldRaphael.is) : delete Raphael;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3349
        return R;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3350
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3351
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3352
    R.st = setproto;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3353
    // Firefox <3.6 fix: http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3354
    (function (doc, loaded, f) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3355
        if (doc.readyState == null && doc.addEventListener){
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3356
            doc.addEventListener(loaded, f = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3357
                doc.removeEventListener(loaded, f, false);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3358
                doc.readyState = "complete";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3359
            }, false);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3360
            doc.readyState = "loading";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3361
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3362
        function isLoaded() {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3363
            (/in/).test(doc.readyState) ? setTimeout(isLoaded, 9) : R.eve("DOMload");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3364
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3365
        isLoaded();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3366
    })(document, "DOMContentLoaded");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3367
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3368
    oldRaphael.was ? (g.win.Raphael = R) : (Raphael = R);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3369
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3370
    eve.on("DOMload", function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3371
        loaded = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3372
    });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3373
})();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3374
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3375
// ┌─────────────────────────────────────────────────────────────────────┐ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3376
// │ Raphaël 2 - JavaScript Vector Library                               │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3377
// ├─────────────────────────────────────────────────────────────────────┤ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3378
// │ SVG Module                                                          │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3379
// ├─────────────────────────────────────────────────────────────────────┤ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3380
// │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com)   │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3381
// │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com)             │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3382
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3383
// └─────────────────────────────────────────────────────────────────────┘ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3384
window.Raphael.svg && function (R) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3385
    var has = "hasOwnProperty",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3386
        Str = String,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3387
        toFloat = parseFloat,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3388
        toInt = parseInt,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3389
        math = Math,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3390
        mmax = math.max,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3391
        abs = math.abs,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3392
        pow = math.pow,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3393
        separator = /[, ]+/,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3394
        eve = R.eve,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3395
        E = "",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3396
        S = " ";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3397
    var xlink = "http://www.w3.org/1999/xlink",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3398
        markers = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3399
            block: "M5,0 0,2.5 5,5z",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3400
            classic: "M5,0 0,2.5 5,5 3.5,3 3.5,2z",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3401
            diamond: "M2.5,0 5,2.5 2.5,5 0,2.5z",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3402
            open: "M6,1 1,3.5 6,6",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3403
            oval: "M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3404
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3405
        markerCounter = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3406
    R.toString = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3407
        return  "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3408
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3409
    var $ = function (el, attr) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3410
        if (attr) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3411
            if (typeof el == "string") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3412
                el = $(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3413
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3414
            for (var key in attr) if (attr[has](key)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3415
                if (key.substring(0, 6) == "xlink:") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3416
                    el.setAttributeNS(xlink, key.substring(6), Str(attr[key]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3417
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3418
                    el.setAttribute(key, Str(attr[key]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3419
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3420
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3421
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3422
            el = R._g.doc.createElementNS("http://www.w3.org/2000/svg", el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3423
            el.style && (el.style.webkitTapHighlightColor = "rgba(0,0,0,0)");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3424
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3425
        return el;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3426
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3427
    gradients = {},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3428
    rgGrad = /^url\(#(.*)\)$/,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3429
    removeGradientFill = function (node, paper) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3430
        var oid = node.getAttribute("fill");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3431
        oid = oid && oid.match(rgGrad);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3432
        if (oid && !--gradients[oid[1]]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3433
            delete gradients[oid[1]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3434
            paper.defs.removeChild(R._g.doc.getElementById(oid[1]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3435
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3436
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3437
    addGradientFill = function (element, gradient) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3438
        var type = "linear",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3439
            id = element.id + gradient,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3440
            fx = .5, fy = .5,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3441
            o = element.node,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3442
            SVG = element.paper,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3443
            s = o.style,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3444
            el = R._g.doc.getElementById(id);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3445
        if (!el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3446
            gradient = Str(gradient).replace(R._radial_gradient, function (all, _fx, _fy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3447
                type = "radial";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3448
                if (_fx && _fy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3449
                    fx = toFloat(_fx);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3450
                    fy = toFloat(_fy);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3451
                    var dir = ((fy > .5) * 2 - 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3452
                    pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3453
                        (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3454
                        fy != .5 &&
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3455
                        (fy = fy.toFixed(5) - 1e-5 * dir);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3456
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3457
                return E;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3458
            });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3459
            gradient = gradient.split(/\s*\-\s*/);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3460
            if (type == "linear") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3461
                var angle = gradient.shift();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3462
                angle = -toFloat(angle);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3463
                if (isNaN(angle)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3464
                    return null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3465
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3466
                var vector = [0, 0, math.cos(R.rad(angle)), math.sin(R.rad(angle))],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3467
                    max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3468
                vector[2] *= max;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3469
                vector[3] *= max;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3470
                if (vector[2] < 0) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3471
                    vector[0] = -vector[2];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3472
                    vector[2] = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3473
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3474
                if (vector[3] < 0) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3475
                    vector[1] = -vector[3];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3476
                    vector[3] = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3477
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3478
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3479
            var dots = R._parseDots(gradient);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3480
            if (!dots) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3481
                return null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3482
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3483
            if (element.gradient) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3484
                SVG.defs.removeChild(element.gradient);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3485
                delete element.gradient;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3486
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3487
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3488
            id = id.replace(/[\(\)\s,\xb0#]/g, "-");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3489
            el = $(type + "Gradient", {id: id});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3490
            element.gradient = el;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3491
            $(el, type == "radial" ? {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3492
                fx: fx,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3493
                fy: fy
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3494
            } : {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3495
                x1: vector[0],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3496
                y1: vector[1],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3497
                x2: vector[2],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3498
                y2: vector[3],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3499
                gradientTransform: element.matrix.invert()
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3500
            });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3501
            SVG.defs.appendChild(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3502
            for (var i = 0, ii = dots.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3503
                el.appendChild($("stop", {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3504
                    offset: dots[i].offset ? dots[i].offset : i ? "100%" : "0%",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3505
                    "stop-color": dots[i].color || "#fff"
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3506
                }));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3507
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3508
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3509
        $(o, {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3510
            fill: "url(#" + id + ")",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3511
            opacity: 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3512
            "fill-opacity": 1
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3513
        });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3514
        s.fill = E;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3515
        s.opacity = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3516
        s.fillOpacity = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3517
        return 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3518
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3519
    updatePosition = function (o) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3520
        var bbox = o.getBBox(1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3521
        $(o.pattern, {patternTransform: o.matrix.invert() + " translate(" + bbox.x + "," + bbox.y + ")"});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3522
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3523
    addArrow = function (o, value, isEnd) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3524
        if (o.type == "path") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3525
            var values = Str(value).toLowerCase().split("-"),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3526
                p = o.paper,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3527
                se = isEnd ? "end" : "start",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3528
                node = o.node,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3529
                attrs = o.attrs,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3530
                stroke = attrs["stroke-width"],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3531
                i = values.length,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3532
                type = "classic",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3533
                from,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3534
                to,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3535
                dx,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3536
                refX,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3537
                attr,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3538
                w = 3,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3539
                h = 3,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3540
                t = 5;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3541
            while (i--) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3542
                switch (values[i]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3543
                    case "block":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3544
                    case "classic":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3545
                    case "oval":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3546
                    case "diamond":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3547
                    case "open":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3548
                    case "none":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3549
                        type = values[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3550
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3551
                    case "wide": h = 5; break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3552
                    case "narrow": h = 2; break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3553
                    case "long": w = 5; break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3554
                    case "short": w = 2; break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3555
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3556
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3557
            if (type == "open") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3558
                w += 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3559
                h += 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3560
                t += 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3561
                dx = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3562
                refX = isEnd ? 4 : 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3563
                attr = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3564
                    fill: "none",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3565
                    stroke: attrs.stroke
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3566
                };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3567
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3568
                refX = dx = w / 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3569
                attr = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3570
                    fill: attrs.stroke,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3571
                    stroke: "none"
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3572
                };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3573
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3574
            if (o._.arrows) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3575
                if (isEnd) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3576
                    o._.arrows.endPath && markerCounter[o._.arrows.endPath]--;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3577
                    o._.arrows.endMarker && markerCounter[o._.arrows.endMarker]--;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3578
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3579
                    o._.arrows.startPath && markerCounter[o._.arrows.startPath]--;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3580
                    o._.arrows.startMarker && markerCounter[o._.arrows.startMarker]--;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3581
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3582
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3583
                o._.arrows = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3584
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3585
            if (type != "none") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3586
                var pathId = "raphael-marker-" + type,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3587
                    markerId = "raphael-marker-" + se + type + w + h;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3588
                if (!R._g.doc.getElementById(pathId)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3589
                    p.defs.appendChild($($("path"), {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3590
                        "stroke-linecap": "round",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3591
                        d: markers[type],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3592
                        id: pathId
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3593
                    }));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3594
                    markerCounter[pathId] = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3595
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3596
                    markerCounter[pathId]++;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3597
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3598
                var marker = R._g.doc.getElementById(markerId),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3599
                    use;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3600
                if (!marker) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3601
                    marker = $($("marker"), {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3602
                        id: markerId,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3603
                        markerHeight: h,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3604
                        markerWidth: w,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3605
                        orient: "auto",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3606
                        refX: refX,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3607
                        refY: h / 2
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3608
                    });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3609
                    use = $($("use"), {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3610
                        "xlink:href": "#" + pathId,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3611
                        transform: (isEnd ? " rotate(180 " + w / 2 + " " + h / 2 + ") " : S) + "scale(" + w / t + "," + h / t + ")",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3612
                        "stroke-width": 1 / ((w / t + h / t) / 2)
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3613
                    });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3614
                    marker.appendChild(use);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3615
                    p.defs.appendChild(marker);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3616
                    markerCounter[markerId] = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3617
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3618
                    markerCounter[markerId]++;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3619
                    use = marker.getElementsByTagName("use")[0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3620
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3621
                $(use, attr);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3622
                var delta = dx * (type != "diamond" && type != "oval");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3623
                if (isEnd) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3624
                    from = o._.arrows.startdx * stroke || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3625
                    to = R.getTotalLength(attrs.path) - delta * stroke;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3626
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3627
                    from = delta * stroke;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3628
                    to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3629
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3630
                attr = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3631
                attr["marker-" + se] = "url(#" + markerId + ")";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3632
                if (to || from) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3633
                    attr.d = Raphael.getSubpath(attrs.path, from, to);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3634
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3635
                $(node, attr);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3636
                o._.arrows[se + "Path"] = pathId;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3637
                o._.arrows[se + "Marker"] = markerId;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3638
                o._.arrows[se + "dx"] = delta;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3639
                o._.arrows[se + "Type"] = type;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3640
                o._.arrows[se + "String"] = value;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3641
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3642
                if (isEnd) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3643
                    from = o._.arrows.startdx * stroke || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3644
                    to = R.getTotalLength(attrs.path) - from;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3645
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3646
                    from = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3647
                    to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3648
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3649
                o._.arrows[se + "Path"] && $(node, {d: Raphael.getSubpath(attrs.path, from, to)});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3650
                delete o._.arrows[se + "Path"];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3651
                delete o._.arrows[se + "Marker"];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3652
                delete o._.arrows[se + "dx"];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3653
                delete o._.arrows[se + "Type"];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3654
                delete o._.arrows[se + "String"];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3655
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3656
            for (attr in markerCounter) if (markerCounter[has](attr) && !markerCounter[attr]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3657
                var item = R._g.doc.getElementById(attr);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3658
                item && item.parentNode.removeChild(item);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3659
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3660
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3661
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3662
    dasharray = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3663
        "": [0],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3664
        "none": [0],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3665
        "-": [3, 1],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3666
        ".": [1, 1],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3667
        "-.": [3, 1, 1, 1],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3668
        "-..": [3, 1, 1, 1, 1, 1],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3669
        ". ": [1, 3],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3670
        "- ": [4, 3],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3671
        "--": [8, 3],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3672
        "- .": [4, 3, 1, 3],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3673
        "--.": [8, 3, 1, 3],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3674
        "--..": [8, 3, 1, 3, 1, 3]
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3675
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3676
    addDashes = function (o, value, params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3677
        value = dasharray[Str(value).toLowerCase()];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3678
        if (value) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3679
            var width = o.attrs["stroke-width"] || "1",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3680
                butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3681
                dashes = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3682
                i = value.length;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3683
            while (i--) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3684
                dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3685
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3686
            $(o.node, {"stroke-dasharray": dashes.join(",")});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3687
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3688
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3689
    setFillAndStroke = function (o, params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3690
        var node = o.node,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3691
            attrs = o.attrs,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3692
            vis = node.style.visibility;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3693
        node.style.visibility = "hidden";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3694
        for (var att in params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3695
            if (params[has](att)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3696
                if (!R._availableAttrs[has](att)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3697
                    continue;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3698
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3699
                var value = params[att];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3700
                attrs[att] = value;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3701
                switch (att) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3702
                    case "blur":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3703
                        o.blur(value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3704
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3705
                    case "href":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3706
                    case "title":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3707
                    case "target":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3708
                        var pn = node.parentNode;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3709
                        if (pn.tagName.toLowerCase() != "a") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3710
                            var hl = $("a");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3711
                            pn.insertBefore(hl, node);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3712
                            hl.appendChild(node);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3713
                            pn = hl;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3714
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3715
                        if (att == "target" && value == "blank") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3716
                            pn.setAttributeNS(xlink, "show", "new");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3717
                        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3718
                            pn.setAttributeNS(xlink, att, value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3719
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3720
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3721
                    case "cursor":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3722
                        node.style.cursor = value;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3723
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3724
                    case "transform":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3725
                        o.transform(value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3726
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3727
                    case "arrow-start":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3728
                        addArrow(o, value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3729
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3730
                    case "arrow-end":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3731
                        addArrow(o, value, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3732
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3733
                    case "clip-rect":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3734
                        var rect = Str(value).split(separator);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3735
                        if (rect.length == 4) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3736
                            o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3737
                            var el = $("clipPath"),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3738
                                rc = $("rect");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3739
                            el.id = R.createUUID();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3740
                            $(rc, {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3741
                                x: rect[0],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3742
                                y: rect[1],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3743
                                width: rect[2],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3744
                                height: rect[3]
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3745
                            });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3746
                            el.appendChild(rc);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3747
                            o.paper.defs.appendChild(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3748
                            $(node, {"clip-path": "url(#" + el.id + ")"});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3749
                            o.clip = rc;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3750
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3751
                        if (!value) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3752
                            var clip = R._g.doc.getElementById(node.getAttribute("clip-path").replace(/(^url\(#|\)$)/g, E));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3753
                            clip && clip.parentNode.removeChild(clip);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3754
                            $(node, {"clip-path": E});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3755
                            delete o.clip;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3756
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3757
                    break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3758
                    case "path":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3759
                        if (o.type == "path") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3760
                            $(node, {d: value ? attrs.path = R._pathToAbsolute(value) : "M0,0"});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3761
                            o._.dirty = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3762
                            if (o._.arrows) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3763
                                "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3764
                                "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3765
                            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3766
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3767
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3768
                    case "width":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3769
                        node.setAttribute(att, value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3770
                        o._.dirty = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3771
                        if (attrs.fx) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3772
                            att = "x";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3773
                            value = attrs.x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3774
                        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3775
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3776
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3777
                    case "x":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3778
                        if (attrs.fx) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3779
                            value = -attrs.x - (attrs.width || 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3780
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3781
                    case "rx":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3782
                        if (att == "rx" && o.type == "rect") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3783
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3784
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3785
                    case "cx":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3786
                        node.setAttribute(att, value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3787
                        o.pattern && updatePosition(o);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3788
                        o._.dirty = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3789
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3790
                    case "height":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3791
                        node.setAttribute(att, value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3792
                        o._.dirty = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3793
                        if (attrs.fy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3794
                            att = "y";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3795
                            value = attrs.y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3796
                        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3797
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3798
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3799
                    case "y":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3800
                        if (attrs.fy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3801
                            value = -attrs.y - (attrs.height || 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3802
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3803
                    case "ry":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3804
                        if (att == "ry" && o.type == "rect") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3805
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3806
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3807
                    case "cy":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3808
                        node.setAttribute(att, value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3809
                        o.pattern && updatePosition(o);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3810
                        o._.dirty = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3811
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3812
                    case "r":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3813
                        if (o.type == "rect") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3814
                            $(node, {rx: value, ry: value});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3815
                        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3816
                            node.setAttribute(att, value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3817
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3818
                        o._.dirty = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3819
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3820
                    case "src":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3821
                        if (o.type == "image") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3822
                            node.setAttributeNS(xlink, "href", value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3823
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3824
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3825
                    case "stroke-width":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3826
                        if (o._.sx != 1 || o._.sy != 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3827
                            value /= mmax(abs(o._.sx), abs(o._.sy)) || 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3828
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3829
                        if (o.paper._vbSize) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3830
                            value *= o.paper._vbSize;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3831
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3832
                        node.setAttribute(att, value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3833
                        if (attrs["stroke-dasharray"]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3834
                            addDashes(o, attrs["stroke-dasharray"], params);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3835
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3836
                        if (o._.arrows) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3837
                            "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3838
                            "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3839
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3840
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3841
                    case "stroke-dasharray":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3842
                        addDashes(o, value, params);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3843
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3844
                    case "fill":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3845
                        var isURL = Str(value).match(R._ISURL);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3846
                        if (isURL) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3847
                            el = $("pattern");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3848
                            var ig = $("image");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3849
                            el.id = R.createUUID();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3850
                            $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3851
                            $(ig, {x: 0, y: 0, "xlink:href": isURL[1]});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3852
                            el.appendChild(ig);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3853
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3854
                            (function (el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3855
                                R._preload(isURL[1], function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3856
                                    var w = this.offsetWidth,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3857
                                        h = this.offsetHeight;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3858
                                    $(el, {width: w, height: h});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3859
                                    $(ig, {width: w, height: h});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3860
                                    o.paper.safari();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3861
                                });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3862
                            })(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3863
                            o.paper.defs.appendChild(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3864
                            node.style.fill = "url(#" + el.id + ")";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3865
                            $(node, {fill: "url(#" + el.id + ")"});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3866
                            o.pattern = el;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3867
                            o.pattern && updatePosition(o);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3868
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3869
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3870
                        var clr = R.getRGB(value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3871
                        if (!clr.error) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3872
                            delete params.gradient;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3873
                            delete attrs.gradient;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3874
                            !R.is(attrs.opacity, "undefined") &&
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3875
                                R.is(params.opacity, "undefined") &&
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3876
                                $(node, {opacity: attrs.opacity});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3877
                            !R.is(attrs["fill-opacity"], "undefined") &&
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3878
                                R.is(params["fill-opacity"], "undefined") &&
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3879
                                $(node, {"fill-opacity": attrs["fill-opacity"]});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3880
                        } else if ((o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3881
                            if ("opacity" in attrs || "fill-opacity" in attrs) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3882
                                var gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3883
                                if (gradient) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3884
                                    var stops = gradient.getElementsByTagName("stop");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3885
                                    $(stops[stops.length - 1], {"stop-opacity": ("opacity" in attrs ? attrs.opacity : 1) * ("fill-opacity" in attrs ? attrs["fill-opacity"] : 1)});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3886
                                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3887
                            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3888
                            attrs.gradient = value;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3889
                            attrs.fill = "none";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3890
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3891
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3892
                        clr[has]("opacity") && $(node, {"fill-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3893
                    case "stroke":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3894
                        clr = R.getRGB(value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3895
                        node.setAttribute(att, clr.hex);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3896
                        att == "stroke" && clr[has]("opacity") && $(node, {"stroke-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3897
                        if (att == "stroke" && o._.arrows) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3898
                            "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3899
                            "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3900
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3901
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3902
                    case "gradient":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3903
                        (o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3904
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3905
                    case "opacity":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3906
                        if (attrs.gradient && !attrs[has]("stroke-opacity")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3907
                            $(node, {"stroke-opacity": value > 1 ? value / 100 : value});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3908
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3909
                        // fall
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3910
                    case "fill-opacity":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3911
                        if (attrs.gradient) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3912
                            gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3913
                            if (gradient) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3914
                                stops = gradient.getElementsByTagName("stop");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3915
                                $(stops[stops.length - 1], {"stop-opacity": value});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3916
                            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3917
                            break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3918
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3919
                    default:
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3920
                        att == "font-size" && (value = toInt(value, 10) + "px");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3921
                        var cssrule = att.replace(/(\-.)/g, function (w) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3922
                            return w.substring(1).toUpperCase();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3923
                        });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3924
                        node.style[cssrule] = value;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3925
                        o._.dirty = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3926
                        node.setAttribute(att, value);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3927
                        break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3928
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3929
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3930
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3931
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3932
        tuneText(o, params);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3933
        node.style.visibility = vis;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3934
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3935
    leading = 1.2,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3936
    tuneText = function (el, params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3937
        if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3938
            return;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3939
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3940
        var a = el.attrs,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3941
            node = el.node,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3942
            fontSize = node.firstChild ? toInt(R._g.doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3943
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3944
        if (params[has]("text")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3945
            a.text = params.text;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3946
            while (node.firstChild) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3947
                node.removeChild(node.firstChild);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3948
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3949
            var texts = Str(params.text).split("\n"),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3950
                tspans = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3951
                tspan;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3952
            for (var i = 0, ii = texts.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3953
                tspan = $("tspan");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3954
                i && $(tspan, {dy: fontSize * leading, x: a.x});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3955
                tspan.appendChild(R._g.doc.createTextNode(texts[i]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3956
                node.appendChild(tspan);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3957
                tspans[i] = tspan;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3958
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3959
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3960
            tspans = node.getElementsByTagName("tspan");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3961
            for (i = 0, ii = tspans.length; i < ii; i++) if (i) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3962
                $(tspans[i], {dy: fontSize * leading, x: a.x});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3963
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3964
                $(tspans[0], {dy: 0});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3965
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3966
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3967
        $(node, {x: a.x, y: a.y});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3968
        el._.dirty = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3969
        var bb = el._getBBox(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3970
            dif = a.y - (bb.y + bb.height / 2);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3971
        dif && R.is(dif, "finite") && $(tspans[0], {dy: dif});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3972
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3973
    Element = function (node, svg) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3974
        var X = 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3975
            Y = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3976
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3977
        this[0] = this.node = node;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3978
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3979
        node.raphael = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3980
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3981
        this.id = R._oid++;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3982
        node.raphaelid = this.id;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3983
        this.matrix = R.matrix();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3984
        this.realPath = null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3985
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3986
        this.paper = svg;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3987
        this.attrs = this.attrs || {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3988
        this._ = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3989
            transform: [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3990
            sx: 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3991
            sy: 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3992
            deg: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3993
            dx: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3994
            dy: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3995
            dirty: 1
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3996
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3997
        !svg.bottom && (svg.bottom = this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3998
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  3999
        this.prev = svg.top;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4000
        svg.top && (svg.top.next = this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4001
        svg.top = this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4002
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4003
        this.next = null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4004
    },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4005
    elproto = R.el;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4006
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4007
    Element.prototype = elproto;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4008
    elproto.constructor = Element;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4009
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4010
    R._engine.path = function (pathString, SVG) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4011
        var el = $("path");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4012
        SVG.canvas && SVG.canvas.appendChild(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4013
        var p = new Element(el, SVG);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4014
        p.type = "path";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4015
        setFillAndStroke(p, {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4016
            fill: "none",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4017
            stroke: "#000",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4018
            path: pathString
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4019
        });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4020
        return p;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4021
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4022
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4023
    elproto.rotate = function (deg, cx, cy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4024
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4025
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4026
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4027
        deg = Str(deg).split(separator);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4028
        if (deg.length - 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4029
            cx = toFloat(deg[1]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4030
            cy = toFloat(deg[2]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4031
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4032
        deg = toFloat(deg[0]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4033
        (cy == null) && (cx = cy);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4034
        if (cx == null || cy == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4035
            var bbox = this.getBBox(1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4036
            cx = bbox.x + bbox.width / 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4037
            cy = bbox.y + bbox.height / 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4038
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4039
        this.transform(this._.transform.concat([["r", deg, cx, cy]]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4040
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4041
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4042
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4043
    elproto.scale = function (sx, sy, cx, cy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4044
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4045
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4046
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4047
        sx = Str(sx).split(separator);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4048
        if (sx.length - 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4049
            sy = toFloat(sx[1]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4050
            cx = toFloat(sx[2]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4051
            cy = toFloat(sx[3]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4052
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4053
        sx = toFloat(sx[0]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4054
        (sy == null) && (sy = sx);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4055
        (cy == null) && (cx = cy);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4056
        if (cx == null || cy == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4057
            var bbox = this.getBBox(1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4058
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4059
        cx = cx == null ? bbox.x + bbox.width / 2 : cx;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4060
        cy = cy == null ? bbox.y + bbox.height / 2 : cy;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4061
        this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4062
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4063
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4064
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4065
    elproto.translate = function (dx, dy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4066
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4067
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4068
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4069
        dx = Str(dx).split(separator);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4070
        if (dx.length - 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4071
            dy = toFloat(dx[1]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4072
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4073
        dx = toFloat(dx[0]) || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4074
        dy = +dy || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4075
        this.transform(this._.transform.concat([["t", dx, dy]]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4076
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4077
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4078
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4079
    elproto.transform = function (tstr) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4080
        var _ = this._;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4081
        if (tstr == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4082
            return _.transform;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4083
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4084
        R._extractTransform(this, tstr);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4085
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4086
        this.clip && $(this.clip, {transform: this.matrix.invert()});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4087
        this.pattern && updatePosition(this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4088
        this.node && $(this.node, {transform: this.matrix});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4089
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4090
        if (_.sx != 1 || _.sy != 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4091
            var sw = this.attrs[has]("stroke-width") ? this.attrs["stroke-width"] : 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4092
            this.attr({"stroke-width": sw});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4093
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4094
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4095
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4096
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4097
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4098
    elproto.hide = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4099
        !this.removed && this.paper.safari(this.node.style.display = "none");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4100
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4101
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4102
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4103
    elproto.show = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4104
        !this.removed && this.paper.safari(this.node.style.display = "");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4105
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4106
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4107
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4108
    elproto.remove = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4109
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4110
            return;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4111
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4112
        this.paper.__set__ && this.paper.__set__.exclude(this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4113
        eve.unbind("*.*." + this.id);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4114
        R._tear(this, this.paper);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4115
        this.node.parentNode.removeChild(this.node);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4116
        for (var i in this) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4117
            delete this[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4118
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4119
        this.removed = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4120
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4121
    elproto._getBBox = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4122
        if (this.node.style.display == "none") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4123
            this.show();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4124
            var hide = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4125
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4126
        var bbox = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4127
        try {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4128
            bbox = this.node.getBBox();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4129
        } catch(e) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4130
            // Firefox 3.0.x plays badly here
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4131
        } finally {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4132
            bbox = bbox || {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4133
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4134
        hide && this.hide();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4135
        return bbox;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4136
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4137
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4138
    elproto.attr = function (name, value) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4139
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4140
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4141
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4142
        if (name == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4143
            var res = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4144
            for (var a in this.attrs) if (this.attrs[has](a)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4145
                res[a] = this.attrs[a];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4146
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4147
            res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4148
            res.transform = this._.transform;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4149
            return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4150
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4151
        if (value == null && R.is(name, "string")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4152
            if (name == "fill" && this.attrs.fill == "none" && this.attrs.gradient) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4153
                return this.attrs.gradient;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4154
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4155
            if (name == "transform") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4156
                return this._.transform;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4157
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4158
            var names = name.split(separator),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4159
                out = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4160
            for (var i = 0, ii = names.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4161
                name = names[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4162
                if (name in this.attrs) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4163
                    out[name] = this.attrs[name];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4164
                } else if (R.is(this.paper.customAttributes[name], "function")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4165
                    out[name] = this.paper.customAttributes[name].def;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4166
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4167
                    out[name] = R._availableAttrs[name];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4168
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4169
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4170
            return ii - 1 ? out : out[names[0]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4171
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4172
        if (value == null && R.is(name, "array")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4173
            out = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4174
            for (i = 0, ii = name.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4175
                out[name[i]] = this.attr(name[i]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4176
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4177
            return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4178
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4179
        if (value != null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4180
            var params = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4181
            params[name] = value;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4182
        } else if (name != null && R.is(name, "object")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4183
            params = name;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4184
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4185
        for (var key in params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4186
            eve("attr." + key + "." + this.id, this, params[key]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4187
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4188
        for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4189
            var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4190
            this.attrs[key] = params[key];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4191
            for (var subkey in par) if (par[has](subkey)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4192
                params[subkey] = par[subkey];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4193
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4194
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4195
        setFillAndStroke(this, params);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4196
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4197
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4198
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4199
    elproto.toFront = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4200
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4201
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4202
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4203
        this.node.parentNode.appendChild(this.node);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4204
        var svg = this.paper;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4205
        svg.top != this && R._tofront(this, svg);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4206
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4207
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4208
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4209
    elproto.toBack = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4210
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4211
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4212
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4213
        if (this.node.parentNode.firstChild != this.node) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4214
            this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4215
            R._toback(this, this.paper);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4216
            var svg = this.paper;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4217
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4218
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4219
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4220
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4221
    elproto.insertAfter = function (element) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4222
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4223
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4224
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4225
        var node = element.node || element[element.length - 1].node;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4226
        if (node.nextSibling) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4227
            node.parentNode.insertBefore(this.node, node.nextSibling);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4228
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4229
            node.parentNode.appendChild(this.node);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4230
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4231
        R._insertafter(this, element, this.paper);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4232
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4233
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4234
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4235
    elproto.insertBefore = function (element) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4236
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4237
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4238
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4239
        var node = element.node || element[0].node;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4240
        node.parentNode.insertBefore(this.node, node);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4241
        R._insertbefore(this, element, this.paper);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4242
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4243
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4244
    elproto.blur = function (size) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4245
        // Experimental. No Safari support. Use it on your own risk.
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4246
        var t = this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4247
        if (+size !== 0) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4248
            var fltr = $("filter"),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4249
                blur = $("feGaussianBlur");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4250
            t.attrs.blur = size;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4251
            fltr.id = R.createUUID();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4252
            $(blur, {stdDeviation: +size || 1.5});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4253
            fltr.appendChild(blur);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4254
            t.paper.defs.appendChild(fltr);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4255
            t._blur = fltr;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4256
            $(t.node, {filter: "url(#" + fltr.id + ")"});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4257
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4258
            if (t._blur) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4259
                t._blur.parentNode.removeChild(t._blur);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4260
                delete t._blur;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4261
                delete t.attrs.blur;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4262
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4263
            t.node.removeAttribute("filter");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4264
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4265
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4266
    R._engine.circle = function (svg, x, y, r) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4267
        var el = $("circle");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4268
        svg.canvas && svg.canvas.appendChild(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4269
        var res = new Element(el, svg);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4270
        res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4271
        res.type = "circle";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4272
        $(el, res.attrs);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4273
        return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4274
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4275
    R._engine.rect = function (svg, x, y, w, h, r) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4276
        var el = $("rect");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4277
        svg.canvas && svg.canvas.appendChild(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4278
        var res = new Element(el, svg);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4279
        res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4280
        res.type = "rect";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4281
        $(el, res.attrs);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4282
        return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4283
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4284
    R._engine.ellipse = function (svg, x, y, rx, ry) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4285
        var el = $("ellipse");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4286
        svg.canvas && svg.canvas.appendChild(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4287
        var res = new Element(el, svg);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4288
        res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4289
        res.type = "ellipse";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4290
        $(el, res.attrs);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4291
        return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4292
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4293
    R._engine.image = function (svg, src, x, y, w, h) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4294
        var el = $("image");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4295
        $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4296
        el.setAttributeNS(xlink, "href", src);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4297
        svg.canvas && svg.canvas.appendChild(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4298
        var res = new Element(el, svg);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4299
        res.attrs = {x: x, y: y, width: w, height: h, src: src};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4300
        res.type = "image";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4301
        return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4302
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4303
    R._engine.text = function (svg, x, y, text) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4304
        var el = $("text");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4305
        // $(el, {x: x, y: y, "text-anchor": "middle"});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4306
        svg.canvas && svg.canvas.appendChild(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4307
        var res = new Element(el, svg);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4308
        res.attrs = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4309
            x: x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4310
            y: y,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4311
            "text-anchor": "middle",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4312
            text: text,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4313
            font: R._availableAttrs.font,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4314
            stroke: "none",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4315
            fill: "#000"
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4316
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4317
        res.type = "text";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4318
        setFillAndStroke(res, res.attrs);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4319
        return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4320
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4321
    R._engine.setSize = function (width, height) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4322
        this.width = width || this.width;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4323
        this.height = height || this.height;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4324
        this.canvas.setAttribute("width", this.width);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4325
        this.canvas.setAttribute("height", this.height);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4326
        if (this._viewBox) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4327
            this.setViewBox.apply(this, this._viewBox);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4328
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4329
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4330
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4331
    R._engine.create = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4332
        var con = R._getContainer.apply(0, arguments),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4333
            container = con && con.container,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4334
            x = con.x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4335
            y = con.y,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4336
            width = con.width,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4337
            height = con.height;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4338
        if (!container) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4339
            throw new Error("SVG container not found.");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4340
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4341
        var cnvs = $("svg"),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4342
            css = "overflow:hidden;",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4343
            isFloating;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4344
        x = x || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4345
        y = y || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4346
        width = width || 512;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4347
        height = height || 342;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4348
        $(cnvs, {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4349
            height: height,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4350
            version: 1.1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4351
            width: width,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4352
            xmlns: "http://www.w3.org/2000/svg"
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4353
        });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4354
        if (container == 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4355
            cnvs.style.cssText = css + "position:absolute;left:" + x + "px;top:" + y + "px";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4356
            R._g.doc.body.appendChild(cnvs);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4357
            isFloating = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4358
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4359
            cnvs.style.cssText = css + "position:relative";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4360
            if (container.firstChild) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4361
                container.insertBefore(cnvs, container.firstChild);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4362
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4363
                container.appendChild(cnvs);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4364
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4365
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4366
        container = new R._Paper;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4367
        container.width = width;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4368
        container.height = height;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4369
        container.canvas = cnvs;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4370
        // plugins.call(container, container, R.fn);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4371
        container.clear();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4372
        container._left = container._top = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4373
        isFloating && (container.renderfix = function () {});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4374
        container.renderfix();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4375
        return container;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4376
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4377
    R._engine.setViewBox = function (x, y, w, h, fit) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4378
        eve("setViewBox", this, this._viewBox, [x, y, w, h, fit]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4379
        var size = mmax(w / this.width, h / this.height),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4380
            top = this.top,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4381
            aspectRatio = fit ? "meet" : "xMinYMin",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4382
            vb,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4383
            sw;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4384
        if (x == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4385
            if (this._vbSize) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4386
                size = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4387
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4388
            delete this._vbSize;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4389
            vb = "0 0 " + this.width + S + this.height;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4390
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4391
            this._vbSize = size;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4392
            vb = x + S + y + S + w + S + h;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4393
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4394
        $(this.canvas, {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4395
            viewBox: vb,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4396
            preserveAspectRatio: aspectRatio
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4397
        });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4398
        while (size && top) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4399
            sw = "stroke-width" in top.attrs ? top.attrs["stroke-width"] : 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4400
            top.attr({"stroke-width": sw});
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4401
            top._.dirty = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4402
            top._.dirtyT = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4403
            top = top.prev;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4404
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4405
        this._viewBox = [x, y, w, h, !!fit];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4406
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4407
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4408
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4409
    R.prototype.renderfix = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4410
        var cnvs = this.canvas,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4411
            s = cnvs.style,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4412
            pos = cnvs.getScreenCTM() || cnvs.createSVGMatrix(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4413
            left = -pos.e % 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4414
            top = -pos.f % 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4415
        if (left || top) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4416
            if (left) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4417
                this._left = (this._left + left) % 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4418
                s.left = this._left + "px";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4419
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4420
            if (top) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4421
                this._top = (this._top + top) % 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4422
                s.top = this._top + "px";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4423
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4424
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4425
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4426
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4427
    R.prototype.clear = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4428
        R.eve("clear", this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4429
        var c = this.canvas;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4430
        while (c.firstChild) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4431
            c.removeChild(c.firstChild);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4432
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4433
        this.bottom = this.top = null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4434
        (this.desc = $("desc")).appendChild(R._g.doc.createTextNode("Created with Rapha\xebl " + R.version));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4435
        c.appendChild(this.desc);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4436
        c.appendChild(this.defs = $("defs"));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4437
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4438
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4439
    R.prototype.remove = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4440
        eve("remove", this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4441
        this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4442
        for (var i in this) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4443
            this[i] = removed(i);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4444
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4445
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4446
    var setproto = R.st;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4447
    for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4448
        setproto[method] = (function (methodname) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4449
            return function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4450
                var arg = arguments;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4451
                return this.forEach(function (el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4452
                    el[methodname].apply(el, arg);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4453
                });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4454
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4455
        })(method);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4456
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4457
}(window.Raphael);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4458
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4459
// ┌─────────────────────────────────────────────────────────────────────┐ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4460
// │ Raphaël 2 - JavaScript Vector Library                               │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4461
// ├─────────────────────────────────────────────────────────────────────┤ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4462
// │ VML Module                                                          │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4463
// ├─────────────────────────────────────────────────────────────────────┤ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4464
// │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com)   │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4465
// │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com)             │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4466
// │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4467
// └─────────────────────────────────────────────────────────────────────┘ \\
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4468
window.Raphael.vml && function (R) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4469
    var has = "hasOwnProperty",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4470
        Str = String,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4471
        toFloat = parseFloat,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4472
        math = Math,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4473
        round = math.round,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4474
        mmax = math.max,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4475
        mmin = math.min,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4476
        abs = math.abs,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4477
        fillString = "fill",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4478
        separator = /[, ]+/,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4479
        eve = R.eve,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4480
        ms = " progid:DXImageTransform.Microsoft",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4481
        S = " ",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4482
        E = "",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4483
        map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4484
        bites = /([clmz]),?([^clmz]*)/gi,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4485
        blurregexp = / progid:\S+Blur\([^\)]+\)/g,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4486
        val = /-?[^,\s-]+/g,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4487
        cssDot = "position:absolute;left:0;top:0;width:1px;height:1px",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4488
        zoom = 21600,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4489
        pathTypes = {path: 1, rect: 1, image: 1},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4490
        ovalTypes = {circle: 1, ellipse: 1},
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4491
        path2vml = function (path) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4492
            var total =  /[ahqstv]/ig,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4493
                command = R._pathToAbsolute;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4494
            Str(path).match(total) && (command = R._path2curve);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4495
            total = /[clmz]/g;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4496
            if (command == R._pathToAbsolute && !Str(path).match(total)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4497
                var res = Str(path).replace(bites, function (all, command, args) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4498
                    var vals = [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4499
                        isMove = command.toLowerCase() == "m",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4500
                        res = map[command];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4501
                    args.replace(val, function (value) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4502
                        if (isMove && vals.length == 2) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4503
                            res += vals + map[command == "m" ? "l" : "L"];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4504
                            vals = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4505
                        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4506
                        vals.push(round(value * zoom));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4507
                    });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4508
                    return res + vals;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4509
                });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4510
                return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4511
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4512
            var pa = command(path), p, r;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4513
            res = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4514
            for (var i = 0, ii = pa.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4515
                p = pa[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4516
                r = pa[i][0].toLowerCase();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4517
                r == "z" && (r = "x");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4518
                for (var j = 1, jj = p.length; j < jj; j++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4519
                    r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4520
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4521
                res.push(r);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4522
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4523
            return res.join(S);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4524
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4525
        compensation = function (deg, dx, dy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4526
            var m = R.matrix();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4527
            m.rotate(-deg, .5, .5);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4528
            return {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4529
                dx: m.x(dx, dy),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4530
                dy: m.y(dx, dy)
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4531
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4532
        },
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4533
        setCoords = function (p, sx, sy, dx, dy, deg) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4534
            var _ = p._,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4535
                m = p.matrix,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4536
                fillpos = _.fillpos,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4537
                o = p.node,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4538
                s = o.style,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4539
                y = 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4540
                flip = "",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4541
                dxdy,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4542
                kx = zoom / sx,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4543
                ky = zoom / sy;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4544
            s.visibility = "hidden";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4545
            if (!sx || !sy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4546
                return;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4547
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4548
            o.coordsize = abs(kx) + S + abs(ky);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4549
            s.rotation = deg * (sx * sy < 0 ? -1 : 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4550
            if (deg) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4551
                var c = compensation(deg, dx, dy);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4552
                dx = c.dx;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4553
                dy = c.dy;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4554
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4555
            sx < 0 && (flip += "x");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4556
            sy < 0 && (flip += " y") && (y = -1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4557
            s.flip = flip;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4558
            o.coordorigin = (dx * -kx) + S + (dy * -ky);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4559
            if (fillpos || _.fillsize) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4560
                var fill = o.getElementsByTagName(fillString);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4561
                fill = fill && fill[0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4562
                o.removeChild(fill);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4563
                if (fillpos) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4564
                    c = compensation(deg, m.x(fillpos[0], fillpos[1]), m.y(fillpos[0], fillpos[1]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4565
                    fill.position = c.dx * y + S + c.dy * y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4566
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4567
                if (_.fillsize) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4568
                    fill.size = _.fillsize[0] * abs(sx) + S + _.fillsize[1] * abs(sy);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4569
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4570
                o.appendChild(fill);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4571
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4572
            s.visibility = "visible";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4573
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4574
    R.toString = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4575
        return  "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4576
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4577
    addArrow = function (o, value, isEnd) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4578
        var values = Str(value).toLowerCase().split("-"),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4579
            se = isEnd ? "end" : "start",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4580
            i = values.length,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4581
            type = "classic",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4582
            w = "medium",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4583
            h = "medium";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4584
        while (i--) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4585
            switch (values[i]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4586
                case "block":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4587
                case "classic":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4588
                case "oval":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4589
                case "diamond":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4590
                case "open":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4591
                case "none":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4592
                    type = values[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4593
                    break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4594
                case "wide":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4595
                case "narrow": h = values[i]; break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4596
                case "long":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4597
                case "short": w = values[i]; break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4598
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4599
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4600
        var stroke = o.node.getElementsByTagName("stroke")[0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4601
        stroke[se + "arrow"] = type;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4602
        stroke[se + "arrowlength"] = w;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4603
        stroke[se + "arrowwidth"] = h;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4604
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4605
    setFillAndStroke = function (o, params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4606
        // o.paper.canvas.style.display = "none";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4607
        o.attrs = o.attrs || {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4608
        var node = o.node,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4609
            a = o.attrs,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4610
            s = node.style,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4611
            xy,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4612
            newpath = pathTypes[o.type] && (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.cx != a.cx || params.cy != a.cy || params.rx != a.rx || params.ry != a.ry || params.r != a.r),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4613
            isOval = ovalTypes[o.type] && (a.cx != params.cx || a.cy != params.cy || a.r != params.r || a.rx != params.rx || a.ry != params.ry),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4614
            res = o;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4615
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4616
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4617
        for (var par in params) if (params[has](par)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4618
            a[par] = params[par];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4619
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4620
        if (newpath) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4621
            a.path = R._getPath[o.type](o);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4622
            o._.dirty = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4623
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4624
        params.href && (node.href = params.href);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4625
        params.title && (node.title = params.title);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4626
        params.target && (node.target = params.target);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4627
        params.cursor && (s.cursor = params.cursor);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4628
        "blur" in params && o.blur(params.blur);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4629
        if (params.path && o.type == "path" || newpath) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4630
            node.path = path2vml(~Str(a.path).toLowerCase().indexOf("r") ? R._pathToAbsolute(a.path) : a.path);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4631
            if (o.type == "image") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4632
                o._.fillpos = [a.x, a.y];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4633
                o._.fillsize = [a.width, a.height];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4634
                setCoords(o, 1, 1, 0, 0, 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4635
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4636
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4637
        "transform" in params && o.transform(params.transform);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4638
        if (isOval) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4639
            var cx = +a.cx,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4640
                cy = +a.cy,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4641
                rx = +a.rx || +a.r || 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4642
                ry = +a.ry || +a.r || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4643
            node.path = R.format("ar{0},{1},{2},{3},{4},{1},{4},{1}x", round((cx - rx) * zoom), round((cy - ry) * zoom), round((cx + rx) * zoom), round((cy + ry) * zoom), round(cx * zoom));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4644
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4645
        if ("clip-rect" in params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4646
            var rect = Str(params["clip-rect"]).split(separator);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4647
            if (rect.length == 4) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4648
                rect[2] = +rect[2] + (+rect[0]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4649
                rect[3] = +rect[3] + (+rect[1]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4650
                var div = node.clipRect || R._g.doc.createElement("div"),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4651
                    dstyle = div.style;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4652
                dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4653
                if (!node.clipRect) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4654
                    dstyle.position = "absolute";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4655
                    dstyle.top = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4656
                    dstyle.left = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4657
                    dstyle.width = o.paper.width + "px";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4658
                    dstyle.height = o.paper.height + "px";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4659
                    node.parentNode.insertBefore(div, node);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4660
                    div.appendChild(node);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4661
                    node.clipRect = div;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4662
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4663
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4664
            if (!params["clip-rect"]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4665
                node.clipRect && (node.clipRect.style.clip = E);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4666
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4667
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4668
        if (o.textpath) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4669
            var textpathStyle = o.textpath.style;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4670
            params.font && (textpathStyle.font = params.font);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4671
            params["font-family"] && (textpathStyle.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, E) + '"');
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4672
            params["font-size"] && (textpathStyle.fontSize = params["font-size"]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4673
            params["font-weight"] && (textpathStyle.fontWeight = params["font-weight"]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4674
            params["font-style"] && (textpathStyle.fontStyle = params["font-style"]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4675
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4676
        if ("arrow-start" in params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4677
            addArrow(res, params["arrow-start"]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4678
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4679
        if ("arrow-end" in params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4680
            addArrow(res, params["arrow-end"], 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4681
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4682
        if (params.opacity != null || 
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4683
            params["stroke-width"] != null ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4684
            params.fill != null ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4685
            params.src != null ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4686
            params.stroke != null ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4687
            params["stroke-width"] != null ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4688
            params["stroke-opacity"] != null ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4689
            params["fill-opacity"] != null ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4690
            params["stroke-dasharray"] != null ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4691
            params["stroke-miterlimit"] != null ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4692
            params["stroke-linejoin"] != null ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4693
            params["stroke-linecap"] != null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4694
            var fill = node.getElementsByTagName(fillString),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4695
                newfill = false;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4696
            fill = fill && fill[0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4697
            !fill && (newfill = fill = createNode(fillString));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4698
            if (o.type == "image" && params.src) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4699
                fill.src = params.src;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4700
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4701
            params.fill && (fill.on = true);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4702
            if (fill.on == null || params.fill == "none" || params.fill === null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4703
                fill.on = false;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4704
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4705
            if (fill.on && params.fill) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4706
                var isURL = Str(params.fill).match(R._ISURL);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4707
                if (isURL) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4708
                    fill.parentNode == node && node.removeChild(fill);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4709
                    fill.rotate = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4710
                    fill.src = isURL[1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4711
                    fill.type = "tile";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4712
                    var bbox = o.getBBox(1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4713
                    fill.position = bbox.x + S + bbox.y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4714
                    o._.fillpos = [bbox.x, bbox.y];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4715
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4716
                    R._preload(isURL[1], function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4717
                        o._.fillsize = [this.offsetWidth, this.offsetHeight];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4718
                    });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4719
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4720
                    fill.color = R.getRGB(params.fill).hex;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4721
                    fill.src = E;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4722
                    fill.type = "solid";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4723
                    if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill, fill)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4724
                        a.fill = "none";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4725
                        a.gradient = params.fill;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4726
                        fill.rotate = false;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4727
                    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4728
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4729
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4730
            if ("fill-opacity" in params || "opacity" in params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4731
                var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4732
                opacity = mmin(mmax(opacity, 0), 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4733
                fill.opacity = opacity;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4734
                if (fill.src) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4735
                    fill.color = "none";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4736
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4737
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4738
            node.appendChild(fill);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4739
            var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4740
            newstroke = false;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4741
            !stroke && (newstroke = stroke = createNode("stroke"));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4742
            if ((params.stroke && params.stroke != "none") ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4743
                params["stroke-width"] ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4744
                params["stroke-opacity"] != null ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4745
                params["stroke-dasharray"] ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4746
                params["stroke-miterlimit"] ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4747
                params["stroke-linejoin"] ||
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4748
                params["stroke-linecap"]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4749
                stroke.on = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4750
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4751
            (params.stroke == "none" || params.stroke === null || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4752
            var strokeColor = R.getRGB(params.stroke);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4753
            stroke.on && params.stroke && (stroke.color = strokeColor.hex);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4754
            opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4755
            var width = (toFloat(params["stroke-width"]) || 1) * .75;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4756
            opacity = mmin(mmax(opacity, 0), 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4757
            params["stroke-width"] == null && (width = a["stroke-width"]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4758
            params["stroke-width"] && (stroke.weight = width);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4759
            width && width < 1 && (opacity *= width) && (stroke.weight = 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4760
            stroke.opacity = opacity;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4761
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4762
            params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4763
            stroke.miterlimit = params["stroke-miterlimit"] || 8;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4764
            params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4765
            if (params["stroke-dasharray"]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4766
                var dasharray = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4767
                    "-": "shortdash",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4768
                    ".": "shortdot",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4769
                    "-.": "shortdashdot",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4770
                    "-..": "shortdashdotdot",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4771
                    ". ": "dot",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4772
                    "- ": "dash",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4773
                    "--": "longdash",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4774
                    "- .": "dashdot",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4775
                    "--.": "longdashdot",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4776
                    "--..": "longdashdotdot"
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4777
                };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4778
                stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4779
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4780
            newstroke && node.appendChild(stroke);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4781
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4782
        if (res.type == "text") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4783
            res.paper.canvas.style.display = E;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4784
            var span = res.paper.span,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4785
                m = 100,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4786
                fontSize = a.font && a.font.match(/\d+(?:\.\d*)?(?=px)/);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4787
            s = span.style;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4788
            a.font && (s.font = a.font);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4789
            a["font-family"] && (s.fontFamily = a["font-family"]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4790
            a["font-weight"] && (s.fontWeight = a["font-weight"]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4791
            a["font-style"] && (s.fontStyle = a["font-style"]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4792
            fontSize = toFloat(fontSize ? fontSize[0] : a["font-size"]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4793
            s.fontSize = fontSize * m + "px";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4794
            res.textpath.string && (span.innerHTML = Str(res.textpath.string).replace(/</g, "&#60;").replace(/&/g, "&#38;").replace(/\n/g, "<br>"));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4795
            var brect = span.getBoundingClientRect();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4796
            res.W = a.w = (brect.right - brect.left) / m;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4797
            res.H = a.h = (brect.bottom - brect.top) / m;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4798
            // res.paper.canvas.style.display = "none";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4799
            res.X = a.x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4800
            res.Y = a.y + res.H / 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4801
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4802
            ("x" in params || "y" in params) && (res.path.v = R.format("m{0},{1}l{2},{1}", round(a.x * zoom), round(a.y * zoom), round(a.x * zoom) + 1));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4803
            var dirtyattrs = ["x", "y", "text", "font", "font-family", "font-weight", "font-style", "font-size"];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4804
            for (var d = 0, dd = dirtyattrs.length; d < dd; d++) if (dirtyattrs[d] in params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4805
                res._.dirty = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4806
                break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4807
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4808
        
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4809
            // text-anchor emulation
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4810
            switch (a["text-anchor"]) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4811
                case "start":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4812
                    res.textpath.style["v-text-align"] = "left";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4813
                    res.bbx = res.W / 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4814
                break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4815
                case "end":
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4816
                    res.textpath.style["v-text-align"] = "right";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4817
                    res.bbx = -res.W / 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4818
                break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4819
                default:
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4820
                    res.textpath.style["v-text-align"] = "center";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4821
                    res.bbx = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4822
                break;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4823
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4824
            res.textpath.style["v-text-kern"] = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4825
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4826
        // res.paper.canvas.style.display = E;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4827
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4828
    addGradientFill = function (o, gradient, fill) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4829
        o.attrs = o.attrs || {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4830
        var attrs = o.attrs,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4831
            pow = Math.pow,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4832
            opacity,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4833
            oindex,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4834
            type = "linear",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4835
            fxfy = ".5 .5";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4836
        o.attrs.gradient = gradient;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4837
        gradient = Str(gradient).replace(R._radial_gradient, function (all, fx, fy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4838
            type = "radial";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4839
            if (fx && fy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4840
                fx = toFloat(fx);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4841
                fy = toFloat(fy);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4842
                pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4843
                fxfy = fx + S + fy;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4844
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4845
            return E;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4846
        });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4847
        gradient = gradient.split(/\s*\-\s*/);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4848
        if (type == "linear") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4849
            var angle = gradient.shift();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4850
            angle = -toFloat(angle);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4851
            if (isNaN(angle)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4852
                return null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4853
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4854
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4855
        var dots = R._parseDots(gradient);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4856
        if (!dots) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4857
            return null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4858
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4859
        o = o.shape || o.node;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4860
        if (dots.length) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4861
            o.removeChild(fill);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4862
            fill.on = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4863
            fill.method = "none";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4864
            fill.color = dots[0].color;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4865
            fill.color2 = dots[dots.length - 1].color;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4866
            var clrs = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4867
            for (var i = 0, ii = dots.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4868
                dots[i].offset && clrs.push(dots[i].offset + S + dots[i].color);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4869
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4870
            fill.colors = clrs.length ? clrs.join() : "0% " + fill.color;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4871
            if (type == "radial") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4872
                fill.type = "gradientTitle";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4873
                fill.focus = "100%";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4874
                fill.focussize = "0 0";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4875
                fill.focusposition = fxfy;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4876
                fill.angle = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4877
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4878
                // fill.rotate= true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4879
                fill.type = "gradient";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4880
                fill.angle = (270 - angle) % 360;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4881
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4882
            o.appendChild(fill);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4883
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4884
        return 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4885
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4886
    Element = function (node, vml) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4887
        this[0] = this.node = node;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4888
        node.raphael = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4889
        this.id = R._oid++;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4890
        node.raphaelid = this.id;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4891
        this.X = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4892
        this.Y = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4893
        this.attrs = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4894
        this.paper = vml;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4895
        this.matrix = R.matrix();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4896
        this._ = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4897
            transform: [],
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4898
            sx: 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4899
            sy: 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4900
            dx: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4901
            dy: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4902
            deg: 0,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4903
            dirty: 1,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4904
            dirtyT: 1
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4905
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4906
        !vml.bottom && (vml.bottom = this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4907
        this.prev = vml.top;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4908
        vml.top && (vml.top.next = this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4909
        vml.top = this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4910
        this.next = null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4911
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4912
    var elproto = R.el;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4913
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4914
    Element.prototype = elproto;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4915
    elproto.constructor = Element;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4916
    elproto.transform = function (tstr) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4917
        if (tstr == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4918
            return this._.transform;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4919
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4920
        var vbs = this.paper._viewBoxShift,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4921
            vbt = vbs ? "s" + [vbs.scale, vbs.scale] + "-1-1t" + [vbs.dx, vbs.dy] : E,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4922
            oldt;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4923
        if (vbs) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4924
            oldt = tstr = Str(tstr).replace(/\.{3}|\u2026/g, this._.transform || E);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4925
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4926
        R._extractTransform(this, vbt + tstr);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4927
        var matrix = this.matrix.clone(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4928
            skew = this.skew,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4929
            o = this.node,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4930
            split,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4931
            isGrad = ~Str(this.attrs.fill).indexOf("-"),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4932
            isPatt = !Str(this.attrs.fill).indexOf("url(");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4933
        matrix.translate(-.5, -.5);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4934
        if (isPatt || isGrad || this.type == "image") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4935
            skew.matrix = "1 0 0 1";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4936
            skew.offset = "0 0";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4937
            split = matrix.split();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4938
            if ((isGrad && split.noRotation) || !split.isSimple) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4939
                o.style.filter = matrix.toFilter();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4940
                var bb = this.getBBox(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4941
                    bbt = this.getBBox(1),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4942
                    dx = bb.x - bbt.x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4943
                    dy = bb.y - bbt.y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4944
                o.coordorigin = (dx * -zoom) + S + (dy * -zoom);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4945
                setCoords(this, 1, 1, dx, dy, 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4946
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4947
                o.style.filter = E;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4948
                setCoords(this, split.scalex, split.scaley, split.dx, split.dy, split.rotate);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4949
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4950
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4951
            o.style.filter = E;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4952
            skew.matrix = Str(matrix);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4953
            skew.offset = matrix.offset();
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4954
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4955
        oldt && (this._.transform = oldt);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4956
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4957
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4958
    elproto.rotate = function (deg, cx, cy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4959
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4960
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4961
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4962
        if (deg == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4963
            return;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4964
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4965
        deg = Str(deg).split(separator);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4966
        if (deg.length - 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4967
            cx = toFloat(deg[1]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4968
            cy = toFloat(deg[2]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4969
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4970
        deg = toFloat(deg[0]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4971
        (cy == null) && (cx = cy);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4972
        if (cx == null || cy == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4973
            var bbox = this.getBBox(1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4974
            cx = bbox.x + bbox.width / 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4975
            cy = bbox.y + bbox.height / 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4976
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4977
        this._.dirtyT = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4978
        this.transform(this._.transform.concat([["r", deg, cx, cy]]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4979
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4980
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4981
    elproto.translate = function (dx, dy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4982
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4983
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4984
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4985
        dx = Str(dx).split(separator);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4986
        if (dx.length - 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4987
            dy = toFloat(dx[1]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4988
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4989
        dx = toFloat(dx[0]) || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4990
        dy = +dy || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4991
        if (this._.bbox) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4992
            this._.bbox.x += dx;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4993
            this._.bbox.y += dy;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4994
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4995
        this.transform(this._.transform.concat([["t", dx, dy]]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4996
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4997
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4998
    elproto.scale = function (sx, sy, cx, cy) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  4999
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5000
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5001
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5002
        sx = Str(sx).split(separator);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5003
        if (sx.length - 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5004
            sy = toFloat(sx[1]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5005
            cx = toFloat(sx[2]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5006
            cy = toFloat(sx[3]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5007
            isNaN(cx) && (cx = null);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5008
            isNaN(cy) && (cy = null);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5009
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5010
        sx = toFloat(sx[0]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5011
        (sy == null) && (sy = sx);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5012
        (cy == null) && (cx = cy);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5013
        if (cx == null || cy == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5014
            var bbox = this.getBBox(1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5015
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5016
        cx = cx == null ? bbox.x + bbox.width / 2 : cx;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5017
        cy = cy == null ? bbox.y + bbox.height / 2 : cy;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5018
    
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5019
        this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5020
        this._.dirtyT = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5021
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5022
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5023
    elproto.hide = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5024
        !this.removed && (this.node.style.display = "none");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5025
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5026
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5027
    elproto.show = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5028
        !this.removed && (this.node.style.display = E);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5029
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5030
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5031
    elproto._getBBox = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5032
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5033
            return {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5034
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5035
        if (this.type == "text") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5036
            return {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5037
                x: this.X + (this.bbx || 0) - this.W / 2,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5038
                y: this.Y - this.H,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5039
                width: this.W,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5040
                height: this.H
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5041
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5042
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5043
            return pathDimensions(this.attrs.path);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5044
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5045
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5046
    elproto.remove = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5047
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5048
            return;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5049
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5050
        this.paper.__set__ && this.paper.__set__.exclude(this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5051
        R.eve.unbind("*.*." + this.id);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5052
        R._tear(this, this.paper);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5053
        this.node.parentNode.removeChild(this.node);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5054
        this.shape && this.shape.parentNode.removeChild(this.shape);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5055
        for (var i in this) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5056
            delete this[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5057
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5058
        this.removed = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5059
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5060
    elproto.attr = function (name, value) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5061
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5062
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5063
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5064
        if (name == null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5065
            var res = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5066
            for (var a in this.attrs) if (this.attrs[has](a)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5067
                res[a] = this.attrs[a];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5068
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5069
            res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5070
            res.transform = this._.transform;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5071
            return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5072
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5073
        if (value == null && R.is(name, "string")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5074
            if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5075
                return this.attrs.gradient;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5076
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5077
            var names = name.split(separator),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5078
                out = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5079
            for (var i = 0, ii = names.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5080
                name = names[i];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5081
                if (name in this.attrs) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5082
                    out[name] = this.attrs[name];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5083
                } else if (R.is(this.paper.customAttributes[name], "function")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5084
                    out[name] = this.paper.customAttributes[name].def;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5085
                } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5086
                    out[name] = R._availableAttrs[name];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5087
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5088
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5089
            return ii - 1 ? out : out[names[0]];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5090
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5091
        if (this.attrs && value == null && R.is(name, "array")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5092
            out = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5093
            for (i = 0, ii = name.length; i < ii; i++) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5094
                out[name[i]] = this.attr(name[i]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5095
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5096
            return out;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5097
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5098
        var params;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5099
        if (value != null) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5100
            params = {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5101
            params[name] = value;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5102
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5103
        value == null && R.is(name, "object") && (params = name);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5104
        for (var key in params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5105
            eve("attr." + key + "." + this.id, this, params[key]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5106
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5107
        if (params) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5108
            for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5109
                var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5110
                this.attrs[key] = params[key];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5111
                for (var subkey in par) if (par[has](subkey)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5112
                    params[subkey] = par[subkey];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5113
                }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5114
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5115
            // this.paper.canvas.style.display = "none";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5116
            if (params.text && this.type == "text") {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5117
                this.textpath.string = params.text;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5118
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5119
            setFillAndStroke(this, params);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5120
            // this.paper.canvas.style.display = E;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5121
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5122
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5123
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5124
    elproto.toFront = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5125
        !this.removed && this.node.parentNode.appendChild(this.node);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5126
        this.paper && this.paper.top != this && R._tofront(this, this.paper);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5127
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5128
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5129
    elproto.toBack = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5130
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5131
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5132
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5133
        if (this.node.parentNode.firstChild != this.node) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5134
            this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5135
            R._toback(this, this.paper);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5136
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5137
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5138
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5139
    elproto.insertAfter = function (element) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5140
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5141
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5142
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5143
        if (element.constructor == R.st.constructor) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5144
            element = element[element.length - 1];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5145
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5146
        if (element.node.nextSibling) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5147
            element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5148
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5149
            element.node.parentNode.appendChild(this.node);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5150
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5151
        R._insertafter(this, element, this.paper);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5152
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5153
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5154
    elproto.insertBefore = function (element) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5155
        if (this.removed) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5156
            return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5157
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5158
        if (element.constructor == R.st.constructor) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5159
            element = element[0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5160
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5161
        element.node.parentNode.insertBefore(this.node, element.node);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5162
        R._insertbefore(this, element, this.paper);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5163
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5164
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5165
    elproto.blur = function (size) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5166
        var s = this.node.runtimeStyle,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5167
            f = s.filter;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5168
        f = f.replace(blurregexp, E);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5169
        if (+size !== 0) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5170
            this.attrs.blur = size;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5171
            s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5172
            s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5173
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5174
            s.filter = f;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5175
            s.margin = 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5176
            delete this.attrs.blur;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5177
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5178
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5179
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5180
    R._engine.path = function (pathString, vml) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5181
        var el = createNode("shape");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5182
        el.style.cssText = cssDot;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5183
        el.coordsize = zoom + S + zoom;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5184
        el.coordorigin = vml.coordorigin;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5185
        var p = new Element(el, vml),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5186
            attr = {fill: "none", stroke: "#000"};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5187
        pathString && (attr.path = pathString);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5188
        p.type = "path";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5189
        p.path = [];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5190
        p.Path = E;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5191
        setFillAndStroke(p, attr);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5192
        vml.canvas.appendChild(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5193
        var skew = createNode("skew");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5194
        skew.on = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5195
        el.appendChild(skew);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5196
        p.skew = skew;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5197
        p.transform(E);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5198
        return p;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5199
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5200
    R._engine.rect = function (vml, x, y, w, h, r) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5201
        var path = R._rectPath(x, y, w, h, r),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5202
            res = vml.path(path),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5203
            a = res.attrs;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5204
        res.X = a.x = x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5205
        res.Y = a.y = y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5206
        res.W = a.width = w;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5207
        res.H = a.height = h;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5208
        a.r = r;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5209
        a.path = path;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5210
        res.type = "rect";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5211
        return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5212
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5213
    R._engine.ellipse = function (vml, x, y, rx, ry) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5214
        var res = vml.path(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5215
            a = res.attrs;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5216
        res.X = x - rx;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5217
        res.Y = y - ry;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5218
        res.W = rx * 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5219
        res.H = ry * 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5220
        res.type = "ellipse";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5221
        setFillAndStroke(res, {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5222
            cx: x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5223
            cy: y,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5224
            rx: rx,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5225
            ry: ry
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5226
        });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5227
        return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5228
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5229
    R._engine.circle = function (vml, x, y, r) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5230
        var res = vml.path(),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5231
            a = res.attrs;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5232
        res.X = x - r;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5233
        res.Y = y - r;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5234
        res.W = res.H = r * 2;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5235
        res.type = "circle";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5236
        setFillAndStroke(res, {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5237
            cx: x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5238
            cy: y,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5239
            r: r
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5240
        });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5241
        return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5242
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5243
    R._engine.image = function (vml, src, x, y, w, h) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5244
        var path = R._rectPath(x, y, w, h),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5245
            res = vml.path(path).attr({stroke: "none"}),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5246
            a = res.attrs,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5247
            node = res.node,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5248
            fill = node.getElementsByTagName(fillString)[0];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5249
        a.src = src;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5250
        res.X = a.x = x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5251
        res.Y = a.y = y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5252
        res.W = a.width = w;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5253
        res.H = a.height = h;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5254
        a.path = path;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5255
        res.type = "image";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5256
        fill.parentNode == node && node.removeChild(fill);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5257
        fill.rotate = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5258
        fill.src = src;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5259
        fill.type = "tile";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5260
        res._.fillpos = [x, y];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5261
        res._.fillsize = [w, h];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5262
        node.appendChild(fill);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5263
        setCoords(res, 1, 1, 0, 0, 0);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5264
        return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5265
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5266
    R._engine.text = function (vml, x, y, text) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5267
        var el = createNode("shape"),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5268
            path = createNode("path"),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5269
            o = createNode("textpath");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5270
        x = x || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5271
        y = y || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5272
        text = text || "";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5273
        path.v = R.format("m{0},{1}l{2},{1}", round(x * zoom), round(y * zoom), round(x * zoom) + 1);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5274
        path.textpathok = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5275
        o.string = Str(text);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5276
        o.on = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5277
        el.style.cssText = cssDot;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5278
        el.coordsize = zoom + S + zoom;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5279
        el.coordorigin = "0 0";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5280
        var p = new Element(el, vml),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5281
            attr = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5282
                fill: "#000",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5283
                stroke: "none",
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5284
                font: R._availableAttrs.font,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5285
                text: text
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5286
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5287
        p.shape = el;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5288
        p.path = path;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5289
        p.textpath = o;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5290
        p.type = "text";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5291
        p.attrs.text = Str(text);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5292
        p.attrs.x = x;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5293
        p.attrs.y = y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5294
        p.attrs.w = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5295
        p.attrs.h = 1;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5296
        setFillAndStroke(p, attr);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5297
        el.appendChild(o);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5298
        el.appendChild(path);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5299
        vml.canvas.appendChild(el);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5300
        var skew = createNode("skew");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5301
        skew.on = true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5302
        el.appendChild(skew);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5303
        p.skew = skew;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5304
        p.transform(E);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5305
        return p;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5306
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5307
    R._engine.setSize = function (width, height) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5308
        var cs = this.canvas.style;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5309
        this.width = width;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5310
        this.height = height;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5311
        width == +width && (width += "px");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5312
        height == +height && (height += "px");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5313
        cs.width = width;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5314
        cs.height = height;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5315
        cs.clip = "rect(0 " + width + " " + height + " 0)";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5316
        if (this._viewBox) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5317
            setViewBox.apply(this, this._viewBox);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5318
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5319
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5320
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5321
    R._engine.setViewBox = function (x, y, w, h, fit) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5322
        R.eve("setViewBox", this, this._viewBox, [x, y, w, h, fit]);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5323
        var width = this.width,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5324
            height = this.height,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5325
            size = 1 / mmax(w / width, h / height),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5326
            H, W;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5327
        if (fit) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5328
            H = height / h;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5329
            W = width / w;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5330
            if (w * H < width) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5331
                x -= (width - w * H) / 2 / H;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5332
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5333
            if (h * W < height) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5334
                y -= (height - h * W) / 2 / W;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5335
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5336
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5337
        this._viewBox = [x, y, w, h, !!fit];
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5338
        this._viewBoxShift = {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5339
            dx: -x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5340
            dy: -y,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5341
            scale: size
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5342
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5343
        this.forEach(function (el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5344
            el.transform("...");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5345
        });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5346
        return this;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5347
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5348
    var createNode,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5349
        initWin = function (win) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5350
            var doc = win.document;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5351
            doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5352
            try {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5353
                !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5354
                createNode = function (tagName) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5355
                    return doc.createElement('<rvml:' + tagName + ' class="rvml">');
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5356
                };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5357
            } catch (e) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5358
                createNode = function (tagName) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5359
                    return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5360
                };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5361
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5362
        };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5363
    initWin(R._g.win);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5364
    R._engine.create = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5365
        var con = R._getContainer.apply(0, arguments),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5366
            container = con.container,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5367
            height = con.height,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5368
            s,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5369
            width = con.width,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5370
            x = con.x,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5371
            y = con.y;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5372
        if (!container) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5373
            throw new Error("VML container not found.");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5374
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5375
        var res = new R._Paper,
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5376
            c = res.canvas = R._g.doc.createElement("div"),
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5377
            cs = c.style;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5378
        x = x || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5379
        y = y || 0;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5380
        width = width || 512;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5381
        height = height || 342;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5382
        res.width = width;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5383
        res.height = height;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5384
        width == +width && (width += "px");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5385
        height == +height && (height += "px");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5386
        res.coordsize = zoom * 1e3 + S + zoom * 1e3;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5387
        res.coordorigin = "0 0";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5388
        res.span = R._g.doc.createElement("span");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5389
        res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5390
        c.appendChild(res.span);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5391
        cs.cssText = R.format("top:0;left:0;width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden", width, height);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5392
        if (container == 1) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5393
            R._g.doc.body.appendChild(c);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5394
            cs.left = x + "px";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5395
            cs.top = y + "px";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5396
            cs.position = "absolute";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5397
        } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5398
            if (container.firstChild) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5399
                container.insertBefore(c, container.firstChild);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5400
            } else {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5401
                container.appendChild(c);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5402
            }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5403
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5404
        // plugins.call(res, res, R.fn);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5405
        res.renderfix = function () {};
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5406
        return res;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5407
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5408
    R.prototype.clear = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5409
        R.eve("clear", this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5410
        this.canvas.innerHTML = E;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5411
        this.span = R._g.doc.createElement("span");
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5412
        this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5413
        this.canvas.appendChild(this.span);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5414
        this.bottom = this.top = null;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5415
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5416
    R.prototype.remove = function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5417
        R.eve("remove", this);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5418
        this.canvas.parentNode.removeChild(this.canvas);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5419
        for (var i in this) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5420
            this[i] = removed(i);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5421
        }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5422
        return true;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5423
    };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5424
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5425
    var setproto = R.st;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5426
    for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5427
        setproto[method] = (function (methodname) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5428
            return function () {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5429
                var arg = arguments;
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5430
                return this.forEach(function (el) {
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5431
                    el[methodname].apply(el, arg);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5432
                });
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5433
            };
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5434
        })(method);
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5435
    }
a14343a9e897 added raphael.js to the build.
hamidouk
parents:
diff changeset
  5436
}(window.Raphael);