PageRenderTime 110ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/public/js/lib/raphael.js

https://gitlab.com/webster5361/UserFrosting
JavaScript | 8111 lines | 5696 code | 93 blank | 2322 comment | 1780 complexity | c751a1cbe6ccf9aaa97e379046e21555 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, Apache-2.0
  1. // ┌────────────────────────────────────────────────────────────────────┐ \\
  2. // │ Raphaël 2.1.1 - JavaScript Vector Library │ \\
  3. // ├────────────────────────────────────────────────────────────────────┤ \\
  4. // │ Copyright © 2008-2012 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
  5. // │ Copyright © 2008-2012 Sencha Labs (http://sencha.com) │ \\
  6. // ├────────────────────────────────────────────────────────────────────┤ \\
  7. // │ Licensed under the MIT (http://raphaeljs.com/license.html) license.│ \\
  8. // └────────────────────────────────────────────────────────────────────┘ \\
  9. // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
  10. //
  11. // Licensed under the Apache License, Version 2.0 (the "License");
  12. // you may not use this file except in compliance with the License.
  13. // You may obtain a copy of the License at
  14. //
  15. // http://www.apache.org/licenses/LICENSE-2.0
  16. //
  17. // Unless required by applicable law or agreed to in writing, software
  18. // distributed under the License is distributed on an "AS IS" BASIS,
  19. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. // See the License for the specific language governing permissions and
  21. // limitations under the License.
  22. // ┌────────────────────────────────────────────────────────────┐ \\
  23. // │ Eve 0.4.2 - JavaScript Events Library │ \\
  24. // ├────────────────────────────────────────────────────────────┤ \\
  25. // │ Author Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) │ \\
  26. // └────────────────────────────────────────────────────────────┘ \\
  27. (function (glob) {
  28. var version = "0.4.2",
  29. has = "hasOwnProperty",
  30. separator = /[\.\/]/,
  31. wildcard = "*",
  32. fun = function () {},
  33. numsort = function (a, b) {
  34. return a - b;
  35. },
  36. current_event,
  37. stop,
  38. events = {n: {}},
  39. /*\
  40. * eve
  41. [ method ]
  42. * Fires event with given `name`, given scope and other parameters.
  43. > Arguments
  44. - name (string) name of the *event*, dot (`.`) or slash (`/`) separated
  45. - scope (object) context for the event handlers
  46. - varargs (...) the rest of arguments will be sent to event handlers
  47. = (object) array of returned values from the listeners
  48. \*/
  49. eve = function (name, scope) {
  50. name = String(name);
  51. var e = events,
  52. oldstop = stop,
  53. args = Array.prototype.slice.call(arguments, 2),
  54. listeners = eve.listeners(name),
  55. z = 0,
  56. f = false,
  57. l,
  58. indexed = [],
  59. queue = {},
  60. out = [],
  61. ce = current_event,
  62. errors = [];
  63. current_event = name;
  64. stop = 0;
  65. for (var i = 0, ii = listeners.length; i < ii; i++) if ("zIndex" in listeners[i]) {
  66. indexed.push(listeners[i].zIndex);
  67. if (listeners[i].zIndex < 0) {
  68. queue[listeners[i].zIndex] = listeners[i];
  69. }
  70. }
  71. indexed.sort(numsort);
  72. while (indexed[z] < 0) {
  73. l = queue[indexed[z++]];
  74. out.push(l.apply(scope, args));
  75. if (stop) {
  76. stop = oldstop;
  77. return out;
  78. }
  79. }
  80. for (i = 0; i < ii; i++) {
  81. l = listeners[i];
  82. if ("zIndex" in l) {
  83. if (l.zIndex == indexed[z]) {
  84. out.push(l.apply(scope, args));
  85. if (stop) {
  86. break;
  87. }
  88. do {
  89. z++;
  90. l = queue[indexed[z]];
  91. l && out.push(l.apply(scope, args));
  92. if (stop) {
  93. break;
  94. }
  95. } while (l)
  96. } else {
  97. queue[l.zIndex] = l;
  98. }
  99. } else {
  100. out.push(l.apply(scope, args));
  101. if (stop) {
  102. break;
  103. }
  104. }
  105. }
  106. stop = oldstop;
  107. current_event = ce;
  108. return out.length ? out : null;
  109. };
  110. // Undocumented. Debug only.
  111. eve._events = events;
  112. /*\
  113. * eve.listeners
  114. [ method ]
  115. * Internal method which gives you array of all event handlers that will be triggered by the given `name`.
  116. > Arguments
  117. - name (string) name of the event, dot (`.`) or slash (`/`) separated
  118. = (array) array of event handlers
  119. \*/
  120. eve.listeners = function (name) {
  121. var names = name.split(separator),
  122. e = events,
  123. item,
  124. items,
  125. k,
  126. i,
  127. ii,
  128. j,
  129. jj,
  130. nes,
  131. es = [e],
  132. out = [];
  133. for (i = 0, ii = names.length; i < ii; i++) {
  134. nes = [];
  135. for (j = 0, jj = es.length; j < jj; j++) {
  136. e = es[j].n;
  137. items = [e[names[i]], e[wildcard]];
  138. k = 2;
  139. while (k--) {
  140. item = items[k];
  141. if (item) {
  142. nes.push(item);
  143. out = out.concat(item.f || []);
  144. }
  145. }
  146. }
  147. es = nes;
  148. }
  149. return out;
  150. };
  151. /*\
  152. * eve.on
  153. [ method ]
  154. **
  155. * Binds given event handler with a given name. You can use wildcards “`*`” for the names:
  156. | eve.on("*.under.*", f);
  157. | eve("mouse.under.floor"); // triggers f
  158. * Use @eve to trigger the listener.
  159. **
  160. > Arguments
  161. **
  162. - name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
  163. - f (function) event handler function
  164. **
  165. = (function) returned function accepts a single numeric parameter that represents z-index of the handler. It is an optional feature and only used when you need to ensure that some subset of handlers will be invoked in a given order, despite of the order of assignment.
  166. > Example:
  167. | eve.on("mouse", eatIt)(2);
  168. | eve.on("mouse", scream);
  169. | eve.on("mouse", catchIt)(1);
  170. * This will ensure that `catchIt()` function will be called before `eatIt()`.
  171. *
  172. * If you want to put your handler before non-indexed handlers, specify a negative value.
  173. * Note: I assume most of the time you don’t need to worry about z-index, but it’s nice to have this feature “just in case”.
  174. \*/
  175. eve.on = function (name, f) {
  176. name = String(name);
  177. if (typeof f != "function") {
  178. return function () {};
  179. }
  180. var names = name.split(separator),
  181. e = events;
  182. for (var i = 0, ii = names.length; i < ii; i++) {
  183. e = e.n;
  184. e = e.hasOwnProperty(names[i]) && e[names[i]] || (e[names[i]] = {n: {}});
  185. }
  186. e.f = e.f || [];
  187. for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) {
  188. return fun;
  189. }
  190. e.f.push(f);
  191. return function (zIndex) {
  192. if (+zIndex == +zIndex) {
  193. f.zIndex = +zIndex;
  194. }
  195. };
  196. };
  197. /*\
  198. * eve.f
  199. [ method ]
  200. **
  201. * Returns function that will fire given event with optional arguments.
  202. * Arguments that will be passed to the result function will be also
  203. * concated to the list of final arguments.
  204. | el.onclick = eve.f("click", 1, 2);
  205. | eve.on("click", function (a, b, c) {
  206. | console.log(a, b, c); // 1, 2, [event object]
  207. | });
  208. > Arguments
  209. - event (string) event name
  210. - varargs (…) and any other arguments
  211. = (function) possible event handler function
  212. \*/
  213. eve.f = function (event) {
  214. var attrs = [].slice.call(arguments, 1);
  215. return function () {
  216. eve.apply(null, [event, null].concat(attrs).concat([].slice.call(arguments, 0)));
  217. };
  218. };
  219. /*\
  220. * eve.stop
  221. [ method ]
  222. **
  223. * Is used inside an event handler to stop the event, preventing any subsequent listeners from firing.
  224. \*/
  225. eve.stop = function () {
  226. stop = 1;
  227. };
  228. /*\
  229. * eve.nt
  230. [ method ]
  231. **
  232. * Could be used inside event handler to figure out actual name of the event.
  233. **
  234. > Arguments
  235. **
  236. - subname (string) #optional subname of the event
  237. **
  238. = (string) name of the event, if `subname` is not specified
  239. * or
  240. = (boolean) `true`, if current event’s name contains `subname`
  241. \*/
  242. eve.nt = function (subname) {
  243. if (subname) {
  244. return new RegExp("(?:\\.|\\/|^)" + subname + "(?:\\.|\\/|$)").test(current_event);
  245. }
  246. return current_event;
  247. };
  248. /*\
  249. * eve.nts
  250. [ method ]
  251. **
  252. * Could be used inside event handler to figure out actual name of the event.
  253. **
  254. **
  255. = (array) names of the event
  256. \*/
  257. eve.nts = function () {
  258. return current_event.split(separator);
  259. };
  260. /*\
  261. * eve.off
  262. [ method ]
  263. **
  264. * Removes given function from the list of event listeners assigned to given name.
  265. * If no arguments specified all the events will be cleared.
  266. **
  267. > Arguments
  268. **
  269. - name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
  270. - f (function) event handler function
  271. \*/
  272. /*\
  273. * eve.unbind
  274. [ method ]
  275. **
  276. * See @eve.off
  277. \*/
  278. eve.off = eve.unbind = function (name, f) {
  279. if (!name) {
  280. eve._events = events = {n: {}};
  281. return;
  282. }
  283. var names = name.split(separator),
  284. e,
  285. key,
  286. splice,
  287. i, ii, j, jj,
  288. cur = [events];
  289. for (i = 0, ii = names.length; i < ii; i++) {
  290. for (j = 0; j < cur.length; j += splice.length - 2) {
  291. splice = [j, 1];
  292. e = cur[j].n;
  293. if (names[i] != wildcard) {
  294. if (e[names[i]]) {
  295. splice.push(e[names[i]]);
  296. }
  297. } else {
  298. for (key in e) if (e[has](key)) {
  299. splice.push(e[key]);
  300. }
  301. }
  302. cur.splice.apply(cur, splice);
  303. }
  304. }
  305. for (i = 0, ii = cur.length; i < ii; i++) {
  306. e = cur[i];
  307. while (e.n) {
  308. if (f) {
  309. if (e.f) {
  310. for (j = 0, jj = e.f.length; j < jj; j++) if (e.f[j] == f) {
  311. e.f.splice(j, 1);
  312. break;
  313. }
  314. !e.f.length && delete e.f;
  315. }
  316. for (key in e.n) if (e.n[has](key) && e.n[key].f) {
  317. var funcs = e.n[key].f;
  318. for (j = 0, jj = funcs.length; j < jj; j++) if (funcs[j] == f) {
  319. funcs.splice(j, 1);
  320. break;
  321. }
  322. !funcs.length && delete e.n[key].f;
  323. }
  324. } else {
  325. delete e.f;
  326. for (key in e.n) if (e.n[has](key) && e.n[key].f) {
  327. delete e.n[key].f;
  328. }
  329. }
  330. e = e.n;
  331. }
  332. }
  333. };
  334. /*\
  335. * eve.once
  336. [ method ]
  337. **
  338. * Binds given event handler with a given name to only run once then unbind itself.
  339. | eve.once("login", f);
  340. | eve("login"); // triggers f
  341. | eve("login"); // no listeners
  342. * Use @eve to trigger the listener.
  343. **
  344. > Arguments
  345. **
  346. - name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
  347. - f (function) event handler function
  348. **
  349. = (function) same return function as @eve.on
  350. \*/
  351. eve.once = function (name, f) {
  352. var f2 = function () {
  353. eve.unbind(name, f2);
  354. return f.apply(this, arguments);
  355. };
  356. return eve.on(name, f2);
  357. };
  358. /*\
  359. * eve.version
  360. [ property (string) ]
  361. **
  362. * Current version of the library.
  363. \*/
  364. eve.version = version;
  365. eve.toString = function () {
  366. return "You are running Eve " + version;
  367. };
  368. (typeof module != "undefined" && module.exports) ? (module.exports = eve) : (typeof define != "undefined" ? (define("eve", [], function() { return eve; })) : (glob.eve = eve));
  369. })(this);
  370. // ┌─────────────────────────────────────────────────────────────────────┐ \\
  371. // │ "Raphaël 2.1.0" - JavaScript Vector Library │ \\
  372. // ├─────────────────────────────────────────────────────────────────────┤ \\
  373. // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
  374. // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
  375. // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
  376. // └─────────────────────────────────────────────────────────────────────┘ \\
  377. (function (glob, factory) {
  378. // AMD support
  379. if (typeof define === "function" && define.amd) {
  380. // Define as an anonymous module
  381. define(["eve"], function( eve ) {
  382. return factory(glob, eve);
  383. });
  384. } else {
  385. // Browser globals (glob is window)
  386. // Raphael adds itself to window
  387. factory(glob, glob.eve);
  388. }
  389. }(this, function (window, eve) {
  390. /*\
  391. * Raphael
  392. [ method ]
  393. **
  394. * Creates a canvas object on which to draw.
  395. * You must do this first, as all future calls to drawing methods
  396. * from this instance will be bound to this canvas.
  397. > Parameters
  398. **
  399. - container (HTMLElement|string) DOM element or its ID which is going to be a parent for drawing surface
  400. - width (number)
  401. - height (number)
  402. - callback (function) #optional callback function which is going to be executed in the context of newly created paper
  403. * or
  404. - x (number)
  405. - y (number)
  406. - width (number)
  407. - height (number)
  408. - callback (function) #optional callback function which is going to be executed in the context of newly created paper
  409. * or
  410. - all (array) (first 3 or 4 elements in the array are equal to [containerID, width, height] or [x, y, width, height]. The rest are element descriptions in format {type: type, <attributes>}). See @Paper.add.
  411. - callback (function) #optional callback function which is going to be executed in the context of newly created paper
  412. * or
  413. - onReadyCallback (function) function that is going to be called on DOM ready event. You can also subscribe to this event via Eve’s “DOMLoad” event. In this case method returns `undefined`.
  414. = (object) @Paper
  415. > Usage
  416. | // Each of the following examples create a canvas
  417. | // that is 320px wide by 200px high.
  418. | // Canvas is created at the viewport’s 10,50 coordinate.
  419. | var paper = Raphael(10, 50, 320, 200);
  420. | // Canvas is created at the top left corner of the #notepad element
  421. | // (or its top right corner in dir="rtl" elements)
  422. | var paper = Raphael(document.getElementById("notepad"), 320, 200);
  423. | // Same as above
  424. | var paper = Raphael("notepad", 320, 200);
  425. | // Image dump
  426. | var set = Raphael(["notepad", 320, 200, {
  427. | type: "rect",
  428. | x: 10,
  429. | y: 10,
  430. | width: 25,
  431. | height: 25,
  432. | stroke: "#f00"
  433. | }, {
  434. | type: "text",
  435. | x: 30,
  436. | y: 40,
  437. | text: "Dump"
  438. | }]);
  439. \*/
  440. function R(first) {
  441. if (R.is(first, "function")) {
  442. return loaded ? first() : eve.on("raphael.DOMload", first);
  443. } else if (R.is(first, array)) {
  444. return R._engine.create[apply](R, first.splice(0, 3 + R.is(first[0], nu))).add(first);
  445. } else {
  446. var args = Array.prototype.slice.call(arguments, 0);
  447. if (R.is(args[args.length - 1], "function")) {
  448. var f = args.pop();
  449. return loaded ? f.call(R._engine.create[apply](R, args)) : eve.on("raphael.DOMload", function () {
  450. f.call(R._engine.create[apply](R, args));
  451. });
  452. } else {
  453. return R._engine.create[apply](R, arguments);
  454. }
  455. }
  456. }
  457. R.version = "2.1.0";
  458. R.eve = eve;
  459. var loaded,
  460. separator = /[, ]+/,
  461. elements = {circle: 1, rect: 1, path: 1, ellipse: 1, text: 1, image: 1},
  462. formatrg = /\{(\d+)\}/g,
  463. proto = "prototype",
  464. has = "hasOwnProperty",
  465. g = {
  466. doc: document,
  467. win: window
  468. },
  469. oldRaphael = {
  470. was: Object.prototype[has].call(g.win, "Raphael"),
  471. is: g.win.Raphael
  472. },
  473. Paper = function () {
  474. /*\
  475. * Paper.ca
  476. [ property (object) ]
  477. **
  478. * Shortcut for @Paper.customAttributes
  479. \*/
  480. /*\
  481. * Paper.customAttributes
  482. [ property (object) ]
  483. **
  484. * If you have a set of attributes that you would like to represent
  485. * as a function of some number you can do it easily with custom attributes:
  486. > Usage
  487. | paper.customAttributes.hue = function (num) {
  488. | num = num % 1;
  489. | return {fill: "hsb(" + num + ", 0.75, 1)"};
  490. | };
  491. | // Custom attribute “hue” will change fill
  492. | // to be given hue with fixed saturation and brightness.
  493. | // Now you can use it like this:
  494. | var c = paper.circle(10, 10, 10).attr({hue: .45});
  495. | // or even like this:
  496. | c.animate({hue: 1}, 1e3);
  497. |
  498. | // You could also create custom attribute
  499. | // with multiple parameters:
  500. | paper.customAttributes.hsb = function (h, s, b) {
  501. | return {fill: "hsb(" + [h, s, b].join(",") + ")"};
  502. | };
  503. | c.attr({hsb: "0.5 .8 1"});
  504. | c.animate({hsb: [1, 0, 0.5]}, 1e3);
  505. \*/
  506. this.ca = this.customAttributes = {};
  507. },
  508. paperproto,
  509. appendChild = "appendChild",
  510. apply = "apply",
  511. concat = "concat",
  512. supportsTouch = ('ontouchstart' in g.win) || g.win.DocumentTouch && g.doc instanceof DocumentTouch, //taken from Modernizr touch test
  513. E = "",
  514. S = " ",
  515. Str = String,
  516. split = "split",
  517. events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel"[split](S),
  518. touchMap = {
  519. mousedown: "touchstart",
  520. mousemove: "touchmove",
  521. mouseup: "touchend"
  522. },
  523. lowerCase = Str.prototype.toLowerCase,
  524. math = Math,
  525. mmax = math.max,
  526. mmin = math.min,
  527. abs = math.abs,
  528. pow = math.pow,
  529. PI = math.PI,
  530. nu = "number",
  531. string = "string",
  532. array = "array",
  533. toString = "toString",
  534. fillString = "fill",
  535. objectToString = Object.prototype.toString,
  536. paper = {},
  537. push = "push",
  538. ISURL = R._ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
  539. 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,
  540. isnan = {"NaN": 1, "Infinity": 1, "-Infinity": 1},
  541. bezierrg = /^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
  542. round = math.round,
  543. setAttribute = "setAttribute",
  544. toFloat = parseFloat,
  545. toInt = parseInt,
  546. upperCase = Str.prototype.toUpperCase,
  547. availableAttrs = R._availableAttrs = {
  548. "arrow-end": "none",
  549. "arrow-start": "none",
  550. blur: 0,
  551. "clip-rect": "0 0 1e9 1e9",
  552. cursor: "default",
  553. cx: 0,
  554. cy: 0,
  555. fill: "#fff",
  556. "fill-opacity": 1,
  557. font: '10px "Arial"',
  558. "font-family": '"Arial"',
  559. "font-size": "10",
  560. "font-style": "normal",
  561. "font-weight": 400,
  562. gradient: 0,
  563. height: 0,
  564. href: "http://raphaeljs.com/",
  565. "letter-spacing": 0,
  566. opacity: 1,
  567. path: "M0,0",
  568. r: 0,
  569. rx: 0,
  570. ry: 0,
  571. src: "",
  572. stroke: "#000",
  573. "stroke-dasharray": "",
  574. "stroke-linecap": "butt",
  575. "stroke-linejoin": "butt",
  576. "stroke-miterlimit": 0,
  577. "stroke-opacity": 1,
  578. "stroke-width": 1,
  579. target: "_blank",
  580. "text-anchor": "middle",
  581. title: "Raphael",
  582. transform: "",
  583. width: 0,
  584. x: 0,
  585. y: 0
  586. },
  587. availableAnimAttrs = R._availableAnimAttrs = {
  588. blur: nu,
  589. "clip-rect": "csv",
  590. cx: nu,
  591. cy: nu,
  592. fill: "colour",
  593. "fill-opacity": nu,
  594. "font-size": nu,
  595. height: nu,
  596. opacity: nu,
  597. path: "path",
  598. r: nu,
  599. rx: nu,
  600. ry: nu,
  601. stroke: "colour",
  602. "stroke-opacity": nu,
  603. "stroke-width": nu,
  604. transform: "transform",
  605. width: nu,
  606. x: nu,
  607. y: nu
  608. },
  609. whitespace = /[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]/g,
  610. commaSpaces = /[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*/,
  611. hsrg = {hs: 1, rg: 1},
  612. p2s = /,?([achlmqrstvxz]),?/gi,
  613. pathCommand = /([achlmrqstvz])[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*)+)/ig,
  614. tCommand = /([rstm])[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*)+)/ig,
  615. pathValues = /(-?\d*\.?\d*(?:e[\-+]?\d+)?)[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*/ig,
  616. radial_gradient = R._radial_gradient = /^r(?:\(([^,]+?)[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*([^\)]+?)\))?/,
  617. eldata = {},
  618. sortByKey = function (a, b) {
  619. return a.key - b.key;
  620. },
  621. sortByNumber = function (a, b) {
  622. return toFloat(a) - toFloat(b);
  623. },
  624. fun = function () {},
  625. pipe = function (x) {
  626. return x;
  627. },
  628. rectPath = R._rectPath = function (x, y, w, h, r) {
  629. if (r) {
  630. 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"]];
  631. }
  632. return [["M", x, y], ["l", w, 0], ["l", 0, h], ["l", -w, 0], ["z"]];
  633. },
  634. ellipsePath = function (x, y, rx, ry) {
  635. if (ry == null) {
  636. ry = rx;
  637. }
  638. 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"]];
  639. },
  640. getPath = R._getPath = {
  641. path: function (el) {
  642. return el.attr("path");
  643. },
  644. circle: function (el) {
  645. var a = el.attrs;
  646. return ellipsePath(a.cx, a.cy, a.r);
  647. },
  648. ellipse: function (el) {
  649. var a = el.attrs;
  650. return ellipsePath(a.cx, a.cy, a.rx, a.ry);
  651. },
  652. rect: function (el) {
  653. var a = el.attrs;
  654. return rectPath(a.x, a.y, a.width, a.height, a.r);
  655. },
  656. image: function (el) {
  657. var a = el.attrs;
  658. return rectPath(a.x, a.y, a.width, a.height);
  659. },
  660. text: function (el) {
  661. var bbox = el._getBBox();
  662. return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
  663. },
  664. set : function(el) {
  665. var bbox = el._getBBox();
  666. return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
  667. }
  668. },
  669. /*\
  670. * Raphael.mapPath
  671. [ method ]
  672. **
  673. * Transform the path string with given matrix.
  674. > Parameters
  675. - path (string) path string
  676. - matrix (object) see @Matrix
  677. = (string) transformed path string
  678. \*/
  679. mapPath = R.mapPath = function (path, matrix) {
  680. if (!matrix) {
  681. return path;
  682. }
  683. var x, y, i, j, ii, jj, pathi;
  684. path = path2curve(path);
  685. for (i = 0, ii = path.length; i < ii; i++) {
  686. pathi = path[i];
  687. for (j = 1, jj = pathi.length; j < jj; j += 2) {
  688. x = matrix.x(pathi[j], pathi[j + 1]);
  689. y = matrix.y(pathi[j], pathi[j + 1]);
  690. pathi[j] = x;
  691. pathi[j + 1] = y;
  692. }
  693. }
  694. return path;
  695. };
  696. R._g = g;
  697. /*\
  698. * Raphael.type
  699. [ property (string) ]
  700. **
  701. * Can be “SVG”, “VML” or empty, depending on browser support.
  702. \*/
  703. R.type = (g.win.SVGAngle || g.doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
  704. if (R.type == "VML") {
  705. var d = g.doc.createElement("div"),
  706. b;
  707. d.innerHTML = '<v:shape adj="1"/>';
  708. b = d.firstChild;
  709. b.style.behavior = "url(#default#VML)";
  710. if (!(b && typeof b.adj == "object")) {
  711. return (R.type = E);
  712. }
  713. d = null;
  714. }
  715. /*\
  716. * Raphael.svg
  717. [ property (boolean) ]
  718. **
  719. * `true` if browser supports SVG.
  720. \*/
  721. /*\
  722. * Raphael.vml
  723. [ property (boolean) ]
  724. **
  725. * `true` if browser supports VML.
  726. \*/
  727. R.svg = !(R.vml = R.type == "VML");
  728. R._Paper = Paper;
  729. /*\
  730. * Raphael.fn
  731. [ property (object) ]
  732. **
  733. * You can add your own method to the canvas. For example if you want to draw a pie chart,
  734. * you can create your own pie chart function and ship it as a Raphaël plugin. To do this
  735. * you need to extend the `Raphael.fn` object. You should modify the `fn` object before a
  736. * Raphaël instance is created, otherwise it will take no effect. Please note that the
  737. * ability for namespaced plugins was removed in Raphael 2.0. It is up to the plugin to
  738. * ensure any namespacing ensures proper context.
  739. > Usage
  740. | Raphael.fn.arrow = function (x1, y1, x2, y2, size) {
  741. | return this.path( ... );
  742. | };
  743. | // or create namespace
  744. | Raphael.fn.mystuff = {
  745. | arrow: function () {…},
  746. | star: function () {…},
  747. | // etc…
  748. | };
  749. | var paper = Raphael(10, 10, 630, 480);
  750. | // then use it
  751. | paper.arrow(10, 10, 30, 30, 5).attr({fill: "#f00"});
  752. | paper.mystuff.arrow();
  753. | paper.mystuff.star();
  754. \*/
  755. R.fn = paperproto = Paper.prototype = R.prototype;
  756. R._id = 0;
  757. R._oid = 0;
  758. /*\
  759. * Raphael.is
  760. [ method ]
  761. **
  762. * Handfull replacement for `typeof` operator.
  763. > Parameters
  764. - o (…) any object or primitive
  765. - type (string) name of the type, i.e. “string”, “function”, “number”, etc.
  766. = (boolean) is given value is of given type
  767. \*/
  768. R.is = function (o, type) {
  769. type = lowerCase.call(type);
  770. if (type == "finite") {
  771. return !isnan[has](+o);
  772. }
  773. if (type == "array") {
  774. return o instanceof Array;
  775. }
  776. return (type == "null" && o === null) ||
  777. (type == typeof o && o !== null) ||
  778. (type == "object" && o === Object(o)) ||
  779. (type == "array" && Array.isArray && Array.isArray(o)) ||
  780. objectToString.call(o).slice(8, -1).toLowerCase() == type;
  781. };
  782. function clone(obj) {
  783. if (typeof obj == "function" || Object(obj) !== obj) {
  784. return obj;
  785. }
  786. var res = new obj.constructor;
  787. for (var key in obj) if (obj[has](key)) {
  788. res[key] = clone(obj[key]);
  789. }
  790. return res;
  791. }
  792. /*\
  793. * Raphael.angle
  794. [ method ]
  795. **
  796. * Returns angle between two or three points
  797. > Parameters
  798. - x1 (number) x coord of first point
  799. - y1 (number) y coord of first point
  800. - x2 (number) x coord of second point
  801. - y2 (number) y coord of second point
  802. - x3 (number) #optional x coord of third point
  803. - y3 (number) #optional y coord of third point
  804. = (number) angle in degrees.
  805. \*/
  806. R.angle = function (x1, y1, x2, y2, x3, y3) {
  807. if (x3 == null) {
  808. var x = x1 - x2,
  809. y = y1 - y2;
  810. if (!x && !y) {
  811. return 0;
  812. }
  813. return (180 + math.atan2(-y, -x) * 180 / PI + 360) % 360;
  814. } else {
  815. return R.angle(x1, y1, x3, y3) - R.angle(x2, y2, x3, y3);
  816. }
  817. };
  818. /*\
  819. * Raphael.rad
  820. [ method ]
  821. **
  822. * Transform angle to radians
  823. > Parameters
  824. - deg (number) angle in degrees
  825. = (number) angle in radians.
  826. \*/
  827. R.rad = function (deg) {
  828. return deg % 360 * PI / 180;
  829. };
  830. /*\
  831. * Raphael.deg
  832. [ method ]
  833. **
  834. * Transform angle to degrees
  835. > Parameters
  836. - deg (number) angle in radians
  837. = (number) angle in degrees.
  838. \*/
  839. R.deg = function (rad) {
  840. return rad * 180 / PI % 360;
  841. };
  842. /*\
  843. * Raphael.snapTo
  844. [ method ]
  845. **
  846. * Snaps given value to given grid.
  847. > Parameters
  848. - values (array|number) given array of values or step of the grid
  849. - value (number) value to adjust
  850. - tolerance (number) #optional tolerance for snapping. Default is `10`.
  851. = (number) adjusted value.
  852. \*/
  853. R.snapTo = function (values, value, tolerance) {
  854. tolerance = R.is(tolerance, "finite") ? tolerance : 10;
  855. if (R.is(values, array)) {
  856. var i = values.length;
  857. while (i--) if (abs(values[i] - value) <= tolerance) {
  858. return values[i];
  859. }
  860. } else {
  861. values = +values;
  862. var rem = value % values;
  863. if (rem < tolerance) {
  864. return value - rem;
  865. }
  866. if (rem > values - tolerance) {
  867. return value - rem + values;
  868. }
  869. }
  870. return value;
  871. };
  872. /*\
  873. * Raphael.createUUID
  874. [ method ]
  875. **
  876. * Returns RFC4122, version 4 ID
  877. \*/
  878. var createUUID = R.createUUID = (function (uuidRegEx, uuidReplacer) {
  879. return function () {
  880. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(uuidRegEx, uuidReplacer).toUpperCase();
  881. };
  882. })(/[xy]/g, function (c) {
  883. var r = math.random() * 16 | 0,
  884. v = c == "x" ? r : (r & 3 | 8);
  885. return v.toString(16);
  886. });
  887. /*\
  888. * Raphael.setWindow
  889. [ method ]
  890. **
  891. * Used when you need to draw in `&lt;iframe>`. Switched window to the iframe one.
  892. > Parameters
  893. - newwin (window) new window object
  894. \*/
  895. R.setWindow = function (newwin) {
  896. eve("raphael.setWindow", R, g.win, newwin);
  897. g.win = newwin;
  898. g.doc = g.win.document;
  899. if (R._engine.initWin) {
  900. R._engine.initWin(g.win);
  901. }
  902. };
  903. var toHex = function (color) {
  904. if (R.vml) {
  905. // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
  906. var trim = /^\s+|\s+$/g;
  907. var bod;
  908. try {
  909. var docum = new ActiveXObject("htmlfile");
  910. docum.write("<body>");
  911. docum.close();
  912. bod = docum.body;
  913. } catch(e) {
  914. bod = createPopup().document.body;
  915. }
  916. var range = bod.createTextRange();
  917. toHex = cacher(function (color) {
  918. try {
  919. bod.style.color = Str(color).replace(trim, E);
  920. var value = range.queryCommandValue("ForeColor");
  921. value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
  922. return "#" + ("000000" + value.toString(16)).slice(-6);
  923. } catch(e) {
  924. return "none";
  925. }
  926. });
  927. } else {
  928. var i = g.doc.createElement("i");
  929. i.title = "Rapha\xebl Colour Picker";
  930. i.style.display = "none";
  931. g.doc.body.appendChild(i);
  932. toHex = cacher(function (color) {
  933. i.style.color = color;
  934. return g.doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
  935. });
  936. }
  937. return toHex(color);
  938. },
  939. hsbtoString = function () {
  940. return "hsb(" + [this.h, this.s, this.b] + ")";
  941. },
  942. hsltoString = function () {
  943. return "hsl(" + [this.h, this.s, this.l] + ")";
  944. },
  945. rgbtoString = function () {
  946. return this.hex;
  947. },
  948. prepareRGB = function (r, g, b) {
  949. if (g == null && R.is(r, "object") && "r" in r && "g" in r && "b" in r) {
  950. b = r.b;
  951. g = r.g;
  952. r = r.r;
  953. }
  954. if (g == null && R.is(r, string)) {
  955. var clr = R.getRGB(r);
  956. r = clr.r;
  957. g = clr.g;
  958. b = clr.b;
  959. }
  960. if (r > 1 || g > 1 || b > 1) {
  961. r /= 255;
  962. g /= 255;
  963. b /= 255;
  964. }
  965. return [r, g, b];
  966. },
  967. packageRGB = function (r, g, b, o) {
  968. r *= 255;
  969. g *= 255;
  970. b *= 255;
  971. var rgb = {
  972. r: r,
  973. g: g,
  974. b: b,
  975. hex: R.rgb(r, g, b),
  976. toString: rgbtoString
  977. };
  978. R.is(o, "finite") && (rgb.opacity = o);
  979. return rgb;
  980. };
  981. /*\
  982. * Raphael.color
  983. [ method ]
  984. **
  985. * Parses the color string and returns object with all values for the given color.
  986. > Parameters
  987. - clr (string) color string in one of the supported formats (see @Raphael.getRGB)
  988. = (object) Combined RGB & HSB object in format:
  989. o {
  990. o r (number) red,
  991. o g (number) green,
  992. o b (number) blue,
  993. o hex (string) color in HTML/CSS format: #••••••,
  994. o error (boolean) `true` if string can’t be parsed,
  995. o h (number) hue,
  996. o s (number) saturation,
  997. o v (number) value (brightness),
  998. o l (number) lightness
  999. o }
  1000. \*/
  1001. R.color = function (clr) {
  1002. var rgb;
  1003. if (R.is(clr, "object") && "h" in clr && "s" in clr && "b" in clr) {
  1004. rgb = R.hsb2rgb(clr);
  1005. clr.r = rgb.r;
  1006. clr.g = rgb.g;
  1007. clr.b = rgb.b;
  1008. clr.hex = rgb.hex;
  1009. } else if (R.is(clr, "object") && "h" in clr && "s" in clr && "l" in clr) {
  1010. rgb = R.hsl2rgb(clr);
  1011. clr.r = rgb.r;
  1012. clr.g = rgb.g;
  1013. clr.b = rgb.b;
  1014. clr.hex = rgb.hex;
  1015. } else {
  1016. if (R.is(clr, "string")) {
  1017. clr = R.getRGB(clr);
  1018. }
  1019. if (R.is(clr, "object") && "r" in clr && "g" in clr && "b" in clr) {
  1020. rgb = R.rgb2hsl(clr);
  1021. clr.h = rgb.h;
  1022. clr.s = rgb.s;
  1023. clr.l = rgb.l;
  1024. rgb = R.rgb2hsb(clr);
  1025. clr.v = rgb.b;
  1026. } else {
  1027. clr = {hex: "none"};
  1028. clr.r = clr.g = clr.b = clr.h = clr.s = clr.v = clr.l = -1;
  1029. }
  1030. }
  1031. clr.toString = rgbtoString;
  1032. return clr;
  1033. };
  1034. /*\
  1035. * Raphael.hsb2rgb
  1036. [ method ]
  1037. **
  1038. * Converts HSB values to RGB object.
  1039. > Parameters
  1040. - h (number) hue
  1041. - s (number) saturation
  1042. - v (number) value or brightness
  1043. = (object) RGB object in format:
  1044. o {
  1045. o r (number) red,
  1046. o g (number) green,
  1047. o b (number) blue,
  1048. o hex (string) color in HTML/CSS format: #••••••
  1049. o }
  1050. \*/
  1051. R.hsb2rgb = function (h, s, v, o) {
  1052. if (this.is(h, "object") && "h" in h && "s" in h && "b" in h) {
  1053. v = h.b;
  1054. s = h.s;
  1055. h = h.h;
  1056. o = h.o;
  1057. }
  1058. h *= 360;
  1059. var R, G, B, X, C;
  1060. h = (h % 360) / 60;
  1061. C = v * s;
  1062. X = C * (1 - abs(h % 2 - 1));
  1063. R = G = B = v - C;
  1064. h = ~~h;
  1065. R += [C, X, 0, 0, X, C][h];
  1066. G += [X, C, C, X, 0, 0][h];
  1067. B += [0, 0, X, C, C, X][h];
  1068. return packageRGB(R, G, B, o);
  1069. };
  1070. /*\
  1071. * Raphael.hsl2rgb
  1072. [ method ]
  1073. **
  1074. * Converts HSL values to RGB object.
  1075. > Parameters
  1076. - h (number) hue
  1077. - s (number) saturation
  1078. - l (number) luminosity
  1079. = (object) RGB object in format:
  1080. o {
  1081. o r (number) red,
  1082. o g (number) green,
  1083. o b (number) blue,
  1084. o hex (string) color in HTML/CSS format: #••••••
  1085. o }
  1086. \*/
  1087. R.hsl2rgb = function (h, s, l, o) {
  1088. if (this.is(h, "object") && "h" in h && "s" in h && "l" in h) {
  1089. l = h.l;
  1090. s = h.s;
  1091. h = h.h;
  1092. }
  1093. if (h > 1 || s > 1 || l > 1) {
  1094. h /= 360;
  1095. s /= 100;
  1096. l /= 100;
  1097. }
  1098. h *= 360;
  1099. var R, G, B, X, C;
  1100. h = (h % 360) / 60;
  1101. C = 2 * s * (l < .5 ? l : 1 - l);
  1102. X = C * (1 - abs(h % 2 - 1));
  1103. R = G = B = l - C / 2;
  1104. h = ~~h;
  1105. R += [C, X, 0, 0, X, C][h];
  1106. G += [X, C, C, X, 0, 0][h];
  1107. B += [0, 0, X, C, C, X][h];
  1108. return packageRGB(R, G, B, o);
  1109. };
  1110. /*\
  1111. * Raphael.rgb2hsb
  1112. [ method ]
  1113. **
  1114. * Converts RGB values to HSB object.
  1115. > Parameters
  1116. - r (number) red
  1117. - g (number) green
  1118. - b (number) blue
  1119. = (object) HSB object in format:
  1120. o {
  1121. o h (number) hue
  1122. o s (number) saturation
  1123. o b (number) brightness
  1124. o }
  1125. \*/
  1126. R.rgb2hsb = function (r, g, b) {
  1127. b = prepareRGB(r, g, b);
  1128. r = b[0];
  1129. g = b[1];
  1130. b = b[2];
  1131. var H, S, V, C;
  1132. V = mmax(r, g, b);
  1133. C = V - mmin(r, g, b);
  1134. H = (C == 0 ? null :
  1135. V == r ? (g - b) / C :
  1136. V == g ? (b - r) / C + 2 :
  1137. (r - g) / C + 4
  1138. );
  1139. H = ((H + 360) % 6) * 60 / 360;
  1140. S = C == 0 ? 0 : C / V;
  1141. return {h: H, s: S, b: V, toString: hsbtoString};
  1142. };
  1143. /*\
  1144. * Raphael.rgb2hsl
  1145. [ method ]
  1146. **
  1147. * Converts RGB values to HSL object.
  1148. > Parameters
  1149. - r (number) red
  1150. - g (number) green
  1151. - b (number) blue
  1152. = (object) HSL object in format:
  1153. o {
  1154. o h (number) hue
  1155. o s (number) saturation
  1156. o l (number) luminosity
  1157. o }
  1158. \*/
  1159. R.rgb2hsl = function (r, g, b) {
  1160. b = prepareRGB(r, g, b);
  1161. r = b[0];
  1162. g = b[1];
  1163. b = b[2];
  1164. var H, S, L, M, m, C;
  1165. M = mmax(r, g, b);
  1166. m = mmin(r, g, b);
  1167. C = M - m;
  1168. H = (C == 0 ? null :
  1169. M == r ? (g - b) / C :
  1170. M == g ? (b - r) / C + 2 :
  1171. (r - g) / C + 4);
  1172. H = ((H + 360) % 6) * 60 / 360;
  1173. L = (M + m) / 2;
  1174. S = (C == 0 ? 0 :
  1175. L < .5 ? C / (2 * L) :
  1176. C / (2 - 2 * L));
  1177. return {h: H, s: S, l: L, toString: hsltoString};
  1178. };
  1179. R._path2string = function () {
  1180. return this.join(",").replace(p2s, "$1");
  1181. };
  1182. function repush(array, item) {
  1183. for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
  1184. return array.push(array.splice(i, 1)[0]);
  1185. }
  1186. }
  1187. function cacher(f, scope, postprocessor) {
  1188. function newf() {
  1189. var arg = Array.prototype.slice.call(arguments, 0),
  1190. args = arg.join("\u2400"),
  1191. cache = newf.cache = newf.cache || {},
  1192. count = newf.count = newf.count || [];
  1193. if (cache[has](args)) {
  1194. repush(count, args);
  1195. return postprocessor ? postprocessor(cache[args]) : cache[args];
  1196. }
  1197. count.length >= 1e3 && delete cache[count.shift()];
  1198. count.push(args);
  1199. cache[args] = f[apply](scope, arg);
  1200. return postprocessor ? postprocessor(cache[args]) : cache[args];
  1201. }
  1202. return newf;
  1203. }
  1204. var preload = R._preload = function (src, f) {
  1205. var img = g.doc.createElement("img");
  1206. img.style.cssText = "position:absolute;left:-9999em;top:-9999em";
  1207. img.onload = function () {
  1208. f.call(this);
  1209. this.onload = null;
  1210. g.doc.body.removeChild(this);
  1211. };
  1212. img.onerror = function () {
  1213. g.doc.body.removeChild(this);
  1214. };
  1215. g.doc.body.appendChild(img);
  1216. img.src = src;
  1217. };
  1218. function clrToString() {
  1219. return this.hex;
  1220. }
  1221. /*\
  1222. * Raphael.getRGB
  1223. [ method ]
  1224. **
  1225. * Parses colour string as RGB object
  1226. > Parameters
  1227. - colour (string) colour string in one of formats:
  1228. # <ul>
  1229. # <li>Colour name (“<code>red</code>”, “<code>green</code>”, “<code>cornflowerblue</code>”, etc)</li>
  1230. # <li>#••• — shortened HTML colour: (“<code>#000</code>”, “<code>#fc0</code>”, etc)</li>
  1231. # <li>#•••••• — full length HTML colour: (“<code>#000000</code>”, “<code>#bd2300</code>”)</li>
  1232. # <li>rgb(•••, •••, •••) — red, green and blue channels’ values: (“<code>rgb(200,&nbsp;100,&nbsp;0)</code>”)</li>
  1233. # <li>rgb(•••%, •••%, •••%) — same as above, but in %: (“<code>rgb(100%,&nbsp;175%,&nbsp;0%)</code>”)</li>
  1234. # <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (“<code>hsb(0.5,&nbsp;0.25,&nbsp;1)</code>”)</li>
  1235. # <li>hsb(•••%, •••%, •••%) — same as above, but in %</li>
  1236. # <li>hsl(•••, •••, •••) — same as hsb</li>
  1237. # <li>hsl(•••%, •••%, •••%) — same as hsb</li>
  1238. # </ul>
  1239. = (object) RGB object in format:
  1240. o {
  1241. o r (number) red,
  1242. o g (number) green,
  1243. o b (number) blue
  1244. o hex (string) color in HTML/CSS format: #••••••,
  1245. o error (boolean) true if string can’t be parsed
  1246. o }
  1247. \*/
  1248. R.getRGB = cacher(function (colour) {
  1249. if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
  1250. return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
  1251. }
  1252. if (colour == "none") {
  1253. return {r: -1, g: -1, b: -1, hex: "none", toString: clrToString};
  1254. }
  1255. !(hsrg[has](colour.toLowerCase().substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
  1256. var res,
  1257. red,
  1258. green,
  1259. blue,
  1260. opacity,
  1261. t,
  1262. values,
  1263. rgb = colour.match(colourRegExp);
  1264. if (rgb) {
  1265. if (rgb[2]) {
  1266. blue = toInt(rgb[2].substring(5), 16);
  1267. green = toInt(rgb[2].substring(3, 5), 16);
  1268. red = toInt(rgb[2].substring(1, 3), 16);
  1269. }
  1270. if (rgb[3]) {
  1271. blue = toInt((t = rgb[3].charAt(3)) + t, 16);
  1272. green = toInt((t = rgb[3].charAt(2)) + t, 16);
  1273. red = toInt((t = rgb[3].charAt(1)) + t, 16);
  1274. }
  1275. if (rgb[4]) {
  1276. values = rgb[4][split](commaSpaces);
  1277. red = toFloat(values[0]);
  1278. values[0].slice(-1) == "%" && (red *= 2.55);
  1279. green = toFloat(values[1]);
  1280. values[1].slice(-1) == "%" && (green *= 2.55);
  1281. blue = toFloat(values[2]);
  1282. values[2].slice(-1) == "%" && (blue *= 2.55);
  1283. rgb[1].toLowerCase().slice(0, 4) == "rgba" && (opacity = toFloat(values[3]));
  1284. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  1285. }
  1286. if (rgb[5]) {
  1287. values = rgb[5][split](commaSpaces);
  1288. red = toFloat(values[0]);
  1289. values[0].slice(-1) == "%" && (red *= 2.55);
  1290. green = toFloat(values[1]);
  1291. values[1].slice(-1) == "%" && (green *= 2.55);
  1292. blue = toFloat(values[2]);
  1293. values[2].slice(-1) == "%" && (blue *= 2.55);
  1294. (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
  1295. rgb[1].toLowerCase().slice(0, 4) == "hsba" && (opacity = toFloat(values[3]));
  1296. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  1297. return R.hsb2rgb(red, green, blue, opacity);
  1298. }
  1299. if (rgb[6]) {
  1300. values = rgb[6][split](commaSpaces);
  1301. red = toFloat(values[0]);
  1302. values[0].slice(-1) == "%" && (red *= 2.55);
  1303. green = toFloat(values[1]);
  1304. values[1].slice(-1) == "%" && (green *= 2.55);
  1305. blue = toFloat(values[2]);
  1306. values[2].slice(-1) == "%" && (blue *= 2.55);
  1307. (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
  1308. rgb[1].toLowerCase().slice(0, 4) == "hsla" && (opacity = toFloat(values[3]));
  1309. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  1310. return R.hsl2rgb(red, green, blue, opacity);
  1311. }
  1312. rgb = {r: red, g: green, b: blue, toString: clrToString};
  1313. rgb.hex = "#" + (16777216 | blue | (green << 8) | (red << 16)).toString(16).slice(1);
  1314. R.is(opacity, "finite") && (rgb.opacity = opacity);
  1315. return rgb;
  1316. }
  1317. return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
  1318. }, R);
  1319. /*\
  1320. * Raphael.hsb
  1321. [ method ]
  1322. **
  1323. * Converts HSB values to hex representation of the colour.
  1324. > Parameters
  1325. - h (number) hue
  1326. - s (number) saturation
  1327. - b (number) value or brightness
  1328. = (string) hex representation of the colour.
  1329. \*/
  1330. R.hsb = cacher(function (h, s, b) {
  1331. return R.hsb2rgb(h, s, b).hex;
  1332. });
  1333. /*\
  1334. * Raphael.hsl
  1335. [ method ]
  1336. **
  1337. * Converts HSL values to hex representation of the colour.
  1338. > Parameters
  1339. - h (number) hue
  1340. - s (number) saturation
  1341. - l (number) luminosity
  1342. = (string) hex representation of the colour.
  1343. \*/
  1344. R.hsl = cacher(function (h, s, l) {
  1345. return R.hsl2rgb(h, s, l).hex;
  1346. });
  1347. /*\
  1348. * Raphael.rgb
  1349. [ method ]
  1350. **
  1351. * Converts RGB values to hex representation of the colour.
  1352. > Parameters
  1353. - r (number) red
  1354. - g (number) green
  1355. - b (number) blue
  1356. = (string) hex representation of the colour.
  1357. \*/
  1358. R.rgb = cacher(function (r, g, b) {
  1359. return "#" + (16777216 | b | (g << 8) | (r << 16)).toString(16).slice(1);
  1360. });
  1361. /*\
  1362. * Raphael.getColor
  1363. [ method ]
  1364. **
  1365. * On each call returns next colour in the spectrum. To reset it back to red call @Raphael.getColor.reset
  1366. > Parameters
  1367. - value (number) #optional brightness, default is `0.75`
  1368. = (string) hex representation of the colour.
  1369. \*/
  1370. R.getColor = function (value) {
  1371. var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
  1372. rgb = this.hsb2rgb(start.h, start.s, start.b);
  1373. start.h += .075;
  1374. if (start.h > 1) {
  1375. start.h = 0;
  1376. start.s -= .2;
  1377. start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
  1378. }
  1379. return rgb.hex;
  1380. };
  1381. /*\
  1382. * Raphael.getColor.reset
  1383. [ method ]
  1384. **
  1385. * Resets spectrum position for @Raphael.getColor back to red.
  1386. \*/
  1387. R.getColor.reset = function () {
  1388. delete this.start;
  1389. };
  1390. // http://schepers.cc/getting-to-the-point
  1391. function catmullRom2bezier(crp, z) {
  1392. var d = [];
  1393. for (var i = 0, iLen = crp.length; iLen - 2 * !z > i; i += 2) {
  1394. var p = [
  1395. {x: +crp[i - 2], y: +crp[i - 1]},
  1396. {x: +crp[i], y: +crp[i + 1]},
  1397. {x: +crp[i + 2], y: +crp[i + 3]},
  1398. {x: +crp[i + 4], y: +crp[i + 5]}
  1399. ];
  1400. if (z) {
  1401. if (!i) {
  1402. p[0] = {x: +crp[iLen - 2], y: +crp[iLen - 1]};
  1403. } else if (iLen - 4 == i) {
  1404. p[3] = {x: +crp[0], y: +crp[1]};
  1405. } else if (iLen - 2 == i) {
  1406. p[2] = {x: +crp[0], y: +crp[1]};
  1407. p[3] = {x: +crp[2], y: +crp[3]};
  1408. }
  1409. } else {
  1410. if (iLen - 4 == i) {
  1411. p[3] = p[2];
  1412. } else if (!i) {
  1413. p[0] = {x: +crp[i], y: +crp[i + 1]};
  1414. }
  1415. }
  1416. d.push(["C",
  1417. (-p[0].x + 6 * p[1].x + p[2].x) / 6,
  1418. (-p[0].y + 6 * p[1].y + p[2].y) / 6,
  1419. (p[1].x + 6 * p[2].x - p[3].x) / 6,
  1420. (p[1].y + 6*p[2].y - p[3].y) / 6,
  1421. p[2].x,
  1422. p[2].y
  1423. ]);
  1424. }
  1425. return d;
  1426. }
  1427. /*\
  1428. * Raphael.parsePathString
  1429. [ method ]
  1430. **
  1431. * Utility method
  1432. **
  1433. * Parses given path string into an array of arrays of path segments.
  1434. > Parameters
  1435. - pathString (string|array) path string or array of segments (in the last case it will be returned straight away)
  1436. = (array) array of segments.
  1437. \*/
  1438. R.parsePathString = function (pathString) {
  1439. if (!pathString) {
  1440. return null;
  1441. }
  1442. var pth = paths(pathString);
  1443. if (pth.arr) {
  1444. return pathClone(pth.arr);
  1445. }
  1446. var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, z: 0},
  1447. data = [];
  1448. if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
  1449. data = pathClone(pathString);
  1450. }
  1451. if (!data.length) {
  1452. Str(pathString).replace(pathCommand, function (a, b, c) {
  1453. var params = [],
  1454. name = b.toLowerCase();
  1455. c.replace(pathValues, function (a, b) {
  1456. b && params.push(+b);
  1457. });
  1458. if (name == "m" && params.length > 2) {
  1459. data.push([b][concat](params.splice(0, 2)));
  1460. name = "l";
  1461. b = b == "m" ? "l" : "L";
  1462. }
  1463. if (name == "r") {
  1464. data.push([b][concat](params));
  1465. } else while (params.length >= paramCounts[name]) {
  1466. data.push([b][concat](params.splice(0, paramCounts[name])));
  1467. if (!paramCounts[name]) {
  1468. break;
  1469. }
  1470. }
  1471. });
  1472. }
  1473. data.toString = R._path2string;
  1474. pth.arr = pathClone(data);
  1475. return data;
  1476. };
  1477. /*\
  1478. * Raphael.parseTransformString
  1479. [ method ]
  1480. **
  1481. * Utility method
  1482. **
  1483. * Parses given path string into an array of transformations.
  1484. > Parameters
  1485. - TString (string|array) transform string or array of transformations (in the last case it will be returned straight away)
  1486. = (array) array of transformations.
  1487. \*/
  1488. R.parseTransformString = cacher(function (TString) {
  1489. if (!TString) {
  1490. return null;
  1491. }
  1492. var paramCounts = {r: 3, s: 4, t: 2, m: 6},
  1493. data = [];
  1494. if (R.is(TString, array) && R.is(TString[0], array)) { // rough assumption
  1495. data = pathClone(TString);
  1496. }
  1497. if (!data.length) {
  1498. Str(TString).replace(tCommand, function (a, b, c) {
  1499. var params = [],
  1500. name = lowerCase.call(b);
  1501. c.replace(pathValues, function (a, b) {
  1502. b && params.push(+b);
  1503. });
  1504. data.push([b][concat](params));
  1505. });
  1506. }
  1507. data.toString = R._path2string;
  1508. return data;
  1509. });
  1510. // PATHS
  1511. var paths = function (ps) {
  1512. var p = paths.ps = paths.ps || {};
  1513. if (p[ps]) {
  1514. p[ps].sleep = 100;
  1515. } else {
  1516. p[ps] = {
  1517. sleep: 100
  1518. };
  1519. }
  1520. setTimeout(function () {
  1521. for (var key in p) if (p[has](key) && key != ps) {
  1522. p[key].sleep--;
  1523. !p[key].sleep && delete p[key];
  1524. }
  1525. });
  1526. return p[ps];
  1527. };
  1528. /*\
  1529. * Raphael.findDotsAtSegment
  1530. [ method ]
  1531. **
  1532. * Utility method
  1533. **
  1534. * Find dot coordinates on the given cubic bezier curve at the given t.
  1535. > Parameters
  1536. - p1x (number) x of the first point of the curve
  1537. - p1y (number) y of the first point of the curve
  1538. - c1x (number) x of the first anchor of the curve
  1539. - c1y (number) y of the first anchor of the curve
  1540. - c2x (number) x of the second anchor of the curve
  1541. - c2y (number) y of the second anchor of the curve
  1542. - p2x (number) x of the second point of the curve
  1543. - p2y (number) y of the second point of the curve
  1544. - t (number) position on the curve (0..1)
  1545. = (object) point information in format:
  1546. o {
  1547. o x: (number) x coordinate of the point
  1548. o y: (number) y coordinate of the point
  1549. o m: {
  1550. o x: (number) x coordinate of the left anchor
  1551. o y: (number) y coordinate of the left anchor
  1552. o }
  1553. o n: {
  1554. o x: (number) x coordinate of the right anchor
  1555. o y: (number) y coordinate of the right anchor
  1556. o }
  1557. o start: {
  1558. o x: (number) x coordinate of the start of the curve
  1559. o y: (number) y coordinate of the start of the curve
  1560. o }
  1561. o end: {
  1562. o x: (number) x coordinate of the end of the curve
  1563. o y: (number) y coordinate of the end of the curve
  1564. o }
  1565. o alpha: (number) angle of the curve derivative at the point
  1566. o }
  1567. \*/
  1568. R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  1569. var t1 = 1 - t,
  1570. t13 = pow(t1, 3),
  1571. t12 = pow(t1, 2),
  1572. t2 = t * t,
  1573. t3 = t2 * t,
  1574. x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x,
  1575. y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y,
  1576. mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x),
  1577. my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y),
  1578. nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x),
  1579. ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y),
  1580. ax = t1 * p1x + t * c1x,
  1581. ay = t1 * p1y + t * c1y,
  1582. cx = t1 * c2x + t * p2x,
  1583. cy = t1 * c2y + t * p2y,
  1584. alpha = (90 - math.atan2(mx - nx, my - ny) * 180 / PI);
  1585. (mx > nx || my < ny) && (alpha += 180);
  1586. return {
  1587. x: x,
  1588. y: y,
  1589. m: {x: mx, y: my},
  1590. n: {x: nx, y: ny},
  1591. start: {x: ax, y: ay},
  1592. end: {x: cx, y: cy},
  1593. alpha: alpha
  1594. };
  1595. };
  1596. /*\
  1597. * Raphael.bezierBBox
  1598. [ method ]
  1599. **
  1600. * Utility method
  1601. **
  1602. * Return bounding box of a given cubic bezier curve
  1603. > Parameters
  1604. - p1x (number) x of the first point of the curve
  1605. - p1y (number) y of the first point of the curve
  1606. - c1x (number) x of the first anchor of the curve
  1607. - c1y (number) y of the first anchor of the curve
  1608. - c2x (number) x of the second anchor of the curve
  1609. - c2y (number) y of the second anchor of the curve
  1610. - p2x (number) x of the second point of the curve
  1611. - p2y (number) y of the second point of the curve
  1612. * or
  1613. - bez (array) array of six points for bezier curve
  1614. = (object) point information in format:
  1615. o {
  1616. o min: {
  1617. o x: (number) x coordinate of the left point
  1618. o y: (number) y coordinate of the top point
  1619. o }
  1620. o max: {
  1621. o x: (number) x coordinate of the right point
  1622. o y: (number) y coordinate of the bottom point
  1623. o }
  1624. o }
  1625. \*/
  1626. R.bezierBBox = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
  1627. if (!R.is(p1x, "array")) {
  1628. p1x = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y];
  1629. }
  1630. var bbox = curveDim.apply(null, p1x);
  1631. return {
  1632. x: bbox.min.x,
  1633. y: bbox.min.y,
  1634. x2: bbox.max.x,
  1635. y2: bbox.max.y,
  1636. width: bbox.max.x - bbox.min.x,
  1637. height: bbox.max.y - bbox.min.y
  1638. };
  1639. };
  1640. /*\
  1641. * Raphael.isPointInsideBBox
  1642. [ method ]
  1643. **
  1644. * Utility method
  1645. **
  1646. * Returns `true` if given point is inside bounding boxes.
  1647. > Parameters
  1648. - bbox (string) bounding box
  1649. - x (string) x coordinate of the point
  1650. - y (string) y coordinate of the point
  1651. = (boolean) `true` if point inside
  1652. \*/
  1653. R.isPointInsideBBox = function (bbox, x, y) {
  1654. return x >= bbox.x && x <= bbox.x2 && y >= bbox.y && y <= bbox.y2;
  1655. };
  1656. /*\
  1657. * Raphael.isBBoxIntersect
  1658. [ method ]
  1659. **
  1660. * Utility method
  1661. **
  1662. * Returns `true` if two bounding boxes intersect
  1663. > Parameters
  1664. - bbox1 (string) first bounding box
  1665. - bbox2 (string) second bounding box
  1666. = (boolean) `true` if they intersect
  1667. \*/
  1668. R.isBBoxIntersect = function (bbox1, bbox2) {
  1669. var i = R.isPointInsideBBox;
  1670. return i(bbox2, bbox1.x, bbox1.y)
  1671. || i(bbox2, bbox1.x2, bbox1.y)
  1672. || i(bbox2, bbox1.x, bbox1.y2)
  1673. || i(bbox2, bbox1.x2, bbox1.y2)
  1674. || i(bbox1, bbox2.x, bbox2.y)
  1675. || i(bbox1, bbox2.x2, bbox2.y)
  1676. || i(bbox1, bbox2.x, bbox2.y2)
  1677. || i(bbox1, bbox2.x2, bbox2.y2)
  1678. || (bbox1.x < bbox2.x2 && bbox1.x > bbox2.x || bbox2.x < bbox1.x2 && bbox2.x > bbox1.x)
  1679. && (bbox1.y < bbox2.y2 && bbox1.y > bbox2.y || bbox2.y < bbox1.y2 && bbox2.y > bbox1.y);
  1680. };
  1681. function base3(t, p1, p2, p3, p4) {
  1682. var t1 = -3 * p1 + 9 * p2 - 9 * p3 + 3 * p4,
  1683. t2 = t * t1 + 6 * p1 - 12 * p2 + 6 * p3;
  1684. return t * t2 - 3 * p1 + 3 * p2;
  1685. }
  1686. function bezlen(x1, y1, x2, y2, x3, y3, x4, y4, z) {
  1687. if (z == null) {
  1688. z = 1;
  1689. }
  1690. z = z > 1 ? 1 : z < 0 ? 0 : z;
  1691. var z2 = z / 2,
  1692. n = 12,
  1693. Tvalues = [-0.1252,0.1252,-0.3678,0.3678,-0.5873,0.5873,-0.7699,0.7699,-0.9041,0.9041,-0.9816,0.9816],
  1694. Cvalues = [0.2491,0.2491,0.2335,0.2335,0.2032,0.2032,0.1601,0.1601,0.1069,0.1069,0.0472,0.0472],
  1695. sum = 0;
  1696. for (var i = 0; i < n; i++) {
  1697. var ct = z2 * Tvalues[i] + z2,
  1698. xbase = base3(ct, x1, x2, x3, x4),
  1699. ybase = base3(ct, y1, y2, y3, y4),
  1700. comb = xbase * xbase + ybase * ybase;
  1701. sum += Cvalues[i] * math.sqrt(comb);
  1702. }
  1703. return z2 * sum;
  1704. }
  1705. function getTatLen(x1, y1, x2, y2, x3, y3, x4, y4, ll) {
  1706. if (ll < 0 || bezlen(x1, y1, x2, y2, x3, y3, x4, y4) < ll) {
  1707. return;
  1708. }
  1709. var t = 1,
  1710. step = t / 2,
  1711. t2 = t - step,
  1712. l,
  1713. e = .01;
  1714. l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2);
  1715. while (abs(l - ll) > e) {
  1716. step /= 2;
  1717. t2 += (l < ll ? 1 : -1) * step;
  1718. l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2);
  1719. }
  1720. return t2;
  1721. }
  1722. function intersect(x1, y1, x2, y2, x3, y3, x4, y4) {
  1723. if (
  1724. mmax(x1, x2) < mmin(x3, x4) ||
  1725. mmin(x1, x2) > mmax(x3, x4) ||
  1726. mmax(y1, y2) < mmin(y3, y4) ||
  1727. mmin(y1, y2) > mmax(y3, y4)
  1728. ) {
  1729. return;
  1730. }
  1731. var nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4),
  1732. ny = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4),
  1733. denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  1734. if (!denominator) {
  1735. return;
  1736. }
  1737. var px = nx / denominator,
  1738. py = ny / denominator,
  1739. px2 = +px.toFixed(2),
  1740. py2 = +py.toFixed(2);
  1741. if (
  1742. px2 < +mmin(x1, x2).toFixed(2) ||
  1743. px2 > +mmax(x1, x2).toFixed(2) ||
  1744. px2 < +mmin(x3, x4).toFixed(2) ||
  1745. px2 > +mmax(x3, x4).toFixed(2) ||
  1746. py2 < +mmin(y1, y2).toFixed(2) ||
  1747. py2 > +mmax(y1, y2).toFixed(2) ||
  1748. py2 < +mmin(y3, y4).toFixed(2) ||
  1749. py2 > +mmax(y3, y4).toFixed(2)
  1750. ) {
  1751. return;
  1752. }
  1753. return {x: px, y: py};
  1754. }
  1755. function inter(bez1, bez2) {
  1756. return interHelper(bez1, bez2);
  1757. }
  1758. function interCount(bez1, bez2) {
  1759. return interHelper(bez1, bez2, 1);
  1760. }
  1761. function interHelper(bez1, bez2, justCount) {
  1762. var bbox1 = R.bezierBBox(bez1),
  1763. bbox2 = R.bezierBBox(bez2);
  1764. if (!R.isBBoxIntersect(bbox1, bbox2)) {
  1765. return justCount ? 0 : [];
  1766. }
  1767. var l1 = bezlen.apply(0, bez1),
  1768. l2 = bezlen.apply(0, bez2),
  1769. n1 = mmax(~~(l1 / 5), 1),
  1770. n2 = mmax(~~(l2 / 5), 1),
  1771. dots1 = [],
  1772. dots2 = [],
  1773. xy = {},
  1774. res = justCount ? 0 : [];
  1775. for (var i = 0; i < n1 + 1; i++) {
  1776. var p = R.findDotsAtSegment.apply(R, bez1.concat(i / n1));
  1777. dots1.push({x: p.x, y: p.y, t: i / n1});
  1778. }
  1779. for (i = 0; i < n2 + 1; i++) {
  1780. p = R.findDotsAtSegment.apply(R, bez2.concat(i / n2));
  1781. dots2.push({x: p.x, y: p.y, t: i / n2});
  1782. }
  1783. for (i = 0; i < n1; i++) {
  1784. for (var j = 0; j < n2; j++) {
  1785. var di = dots1[i],
  1786. di1 = dots1[i + 1],
  1787. dj = dots2[j],
  1788. dj1 = dots2[j + 1],
  1789. ci = abs(di1.x - di.x) < .001 ? "y" : "x",
  1790. cj = abs(dj1.x - dj.x) < .001 ? "y" : "x",
  1791. is = intersect(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y);
  1792. if (is) {
  1793. if (xy[is.x.toFixed(4)] == is.y.toFixed(4)) {
  1794. continue;
  1795. }
  1796. xy[is.x.toFixed(4)] = is.y.toFixed(4);
  1797. var t1 = di.t + abs((is[ci] - di[ci]) / (di1[ci] - di[ci])) * (di1.t - di.t),
  1798. t2 = dj.t + abs((is[cj] - dj[cj]) / (dj1[cj] - dj[cj])) * (dj1.t - dj.t);
  1799. if (t1 >= 0 && t1 <= 1.001 && t2 >= 0 && t2 <= 1.001) {
  1800. if (justCount) {
  1801. res++;
  1802. } else {
  1803. res.push({
  1804. x: is.x,
  1805. y: is.y,
  1806. t1: mmin(t1, 1),
  1807. t2: mmin(t2, 1)
  1808. });
  1809. }
  1810. }
  1811. }
  1812. }
  1813. }
  1814. return res;
  1815. }
  1816. /*\
  1817. * Raphael.pathIntersection
  1818. [ method ]
  1819. **
  1820. * Utility method
  1821. **
  1822. * Finds intersections of two paths
  1823. > Parameters
  1824. - path1 (string) path string
  1825. - path2 (string) path string
  1826. = (array) dots of intersection
  1827. o [
  1828. o {
  1829. o x: (number) x coordinate of the point
  1830. o y: (number) y coordinate of the point
  1831. o t1: (number) t value for segment of path1
  1832. o t2: (number) t value for segment of path2
  1833. o segment1: (number) order number for segment of path1
  1834. o segment2: (number) order number for segment of path2
  1835. o bez1: (array) eight coordinates representing beziér curve for the segment of path1
  1836. o bez2: (array) eight coordinates representing beziér curve for the segment of path2
  1837. o }
  1838. o ]
  1839. \*/
  1840. R.pathIntersection = function (path1, path2) {
  1841. return interPathHelper(path1, path2);
  1842. };
  1843. R.pathIntersectionNumber = function (path1, path2) {
  1844. return interPathHelper(path1, path2, 1);
  1845. };
  1846. function interPathHelper(path1, path2, justCount) {
  1847. path1 = R._path2curve(path1);
  1848. path2 = R._path2curve(path2);
  1849. var x1, y1, x2, y2, x1m, y1m, x2m, y2m, bez1, bez2,
  1850. res = justCount ? 0 : [];
  1851. for (var i = 0, ii = path1.length; i < ii; i++) {
  1852. var pi = path1[i];
  1853. if (pi[0] == "M") {
  1854. x1 = x1m = pi[1];
  1855. y1 = y1m = pi[2];
  1856. } else {
  1857. if (pi[0] == "C") {
  1858. bez1 = [x1, y1].concat(pi.slice(1));
  1859. x1 = bez1[6];
  1860. y1 = bez1[7];
  1861. } else {
  1862. bez1 = [x1, y1, x1, y1, x1m, y1m, x1m, y1m];
  1863. x1 = x1m;
  1864. y1 = y1m;
  1865. }
  1866. for (var j = 0, jj = path2.length; j < jj; j++) {
  1867. var pj = path2[j];
  1868. if (pj[0] == "M") {
  1869. x2 = x2m = pj[1];
  1870. y2 = y2m = pj[2];
  1871. } else {
  1872. if (pj[0] == "C") {
  1873. bez2 = [x2, y2].concat(pj.slice(1));
  1874. x2 = bez2[6];
  1875. y2 = bez2[7];
  1876. } else {
  1877. bez2 = [x2, y2, x2, y2, x2m, y2m, x2m, y2m];
  1878. x2 = x2m;
  1879. y2 = y2m;
  1880. }
  1881. var intr = interHelper(bez1, bez2, justCount);
  1882. if (justCount) {
  1883. res += intr;
  1884. } else {
  1885. for (var k = 0, kk = intr.length; k < kk; k++) {
  1886. intr[k].segment1 = i;
  1887. intr[k].segment2 = j;
  1888. intr[k].bez1 = bez1;
  1889. intr[k].bez2 = bez2;
  1890. }
  1891. res = res.concat(intr);
  1892. }
  1893. }
  1894. }
  1895. }
  1896. }
  1897. return res;
  1898. }
  1899. /*\
  1900. * Raphael.isPointInsidePath
  1901. [ method ]
  1902. **
  1903. * Utility method
  1904. **
  1905. * Returns `true` if given point is inside a given closed path.
  1906. > Parameters
  1907. - path (string) path string
  1908. - x (number) x of the point
  1909. - y (number) y of the point
  1910. = (boolean) true, if point is inside the path
  1911. \*/
  1912. R.isPointInsidePath = function (path, x, y) {
  1913. var bbox = R.pathBBox(path);
  1914. return R.isPointInsideBBox(bbox, x, y) &&
  1915. interPathHelper(path, [["M", x, y], ["H", bbox.x2 + 10]], 1) % 2 == 1;
  1916. };
  1917. R._removedFactory = function (methodname) {
  1918. return function () {
  1919. eve("raphael.log", null, "Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object", methodname);
  1920. };
  1921. };
  1922. /*\
  1923. * Raphael.pathBBox
  1924. [ method ]
  1925. **
  1926. * Utility method
  1927. **
  1928. * Return bounding box of a given path
  1929. > Parameters
  1930. - path (string) path string
  1931. = (object) bounding box
  1932. o {
  1933. o x: (number) x coordinate of the left top point of the box
  1934. o y: (number) y coordinate of the left top point of the box
  1935. o x2: (number) x coordinate of the right bottom point of the box
  1936. o y2: (number) y coordinate of the right bottom point of the box
  1937. o width: (number) width of the box
  1938. o height: (number) height of the box
  1939. o cx: (number) x coordinate of the center of the box
  1940. o cy: (number) y coordinate of the center of the box
  1941. o }
  1942. \*/
  1943. var pathDimensions = R.pathBBox = function (path) {
  1944. var pth = paths(path);
  1945. if (pth.bbox) {
  1946. return clone(pth.bbox);
  1947. }
  1948. if (!path) {
  1949. return {x: 0, y: 0, width: 0, height: 0, x2: 0, y2: 0};
  1950. }
  1951. path = path2curve(path);
  1952. var x = 0,
  1953. y = 0,
  1954. X = [],
  1955. Y = [],
  1956. p;
  1957. for (var i = 0, ii = path.length; i < ii; i++) {
  1958. p = path[i];
  1959. if (p[0] == "M") {
  1960. x = p[1];
  1961. y = p[2];
  1962. X.push(x);
  1963. Y.push(y);
  1964. } else {
  1965. var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
  1966. X = X[concat](dim.min.x, dim.max.x);
  1967. Y = Y[concat](dim.min.y, dim.max.y);
  1968. x = p[5];
  1969. y = p[6];
  1970. }
  1971. }
  1972. var xmin = mmin[apply](0, X),
  1973. ymin = mmin[apply](0, Y),
  1974. xmax = mmax[apply](0, X),
  1975. ymax = mmax[apply](0, Y),
  1976. width = xmax - xmin,
  1977. height = ymax - ymin,
  1978. bb = {
  1979. x: xmin,
  1980. y: ymin,
  1981. x2: xmax,
  1982. y2: ymax,
  1983. width: width,
  1984. height: height,
  1985. cx: xmin + width / 2,
  1986. cy: ymin + height / 2
  1987. };
  1988. pth.bbox = clone(bb);
  1989. return bb;
  1990. },
  1991. pathClone = function (pathArray) {
  1992. var res = clone(pathArray);
  1993. res.toString = R._path2string;
  1994. return res;
  1995. },
  1996. pathToRelative = R._pathToRelative = function (pathArray) {
  1997. var pth = paths(pathArray);
  1998. if (pth.rel) {
  1999. return pathClone(pth.rel);
  2000. }
  2001. if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
  2002. pathArray = R.parsePathString(pathArray);
  2003. }
  2004. var res = [],
  2005. x = 0,
  2006. y = 0,
  2007. mx = 0,
  2008. my = 0,
  2009. start = 0;
  2010. if (pathArray[0][0] == "M") {
  2011. x = pathArray[0][1];
  2012. y = pathArray[0][2];
  2013. mx = x;
  2014. my = y;
  2015. start++;
  2016. res.push(["M", x, y]);
  2017. }
  2018. for (var i = start, ii = pathArray.length; i < ii; i++) {
  2019. var r = res[i] = [],
  2020. pa = pathArray[i];
  2021. if (pa[0] != lowerCase.call(pa[0])) {
  2022. r[0] = lowerCase.call(pa[0]);
  2023. switch (r[0]) {
  2024. case "a":
  2025. r[1] = pa[1];
  2026. r[2] = pa[2];
  2027. r[3] = pa[3];
  2028. r[4] = pa[4];
  2029. r[5] = pa[5];
  2030. r[6] = +(pa[6] - x).toFixed(3);
  2031. r[7] = +(pa[7] - y).toFixed(3);
  2032. break;
  2033. case "v":
  2034. r[1] = +(pa[1] - y).toFixed(3);
  2035. break;
  2036. case "m":
  2037. mx = pa[1];
  2038. my = pa[2];
  2039. default:
  2040. for (var j = 1, jj = pa.length; j < jj; j++) {
  2041. r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
  2042. }
  2043. }
  2044. } else {
  2045. r = res[i] = [];
  2046. if (pa[0] == "m") {
  2047. mx = pa[1] + x;
  2048. my = pa[2] + y;
  2049. }
  2050. for (var k = 0, kk = pa.length; k < kk; k++) {
  2051. res[i][k] = pa[k];
  2052. }
  2053. }
  2054. var len = res[i].length;
  2055. switch (res[i][0]) {
  2056. case "z":
  2057. x = mx;
  2058. y = my;
  2059. break;
  2060. case "h":
  2061. x += +res[i][len - 1];
  2062. break;
  2063. case "v":
  2064. y += +res[i][len - 1];
  2065. break;
  2066. default:
  2067. x += +res[i][len - 2];
  2068. y += +res[i][len - 1];
  2069. }
  2070. }
  2071. res.toString = R._path2string;
  2072. pth.rel = pathClone(res);
  2073. return res;
  2074. },
  2075. pathToAbsolute = R._pathToAbsolute = function (pathArray) {
  2076. var pth = paths(pathArray);
  2077. if (pth.abs) {
  2078. return pathClone(pth.abs);
  2079. }
  2080. if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
  2081. pathArray = R.parsePathString(pathArray);
  2082. }
  2083. if (!pathArray || !pathArray.length) {
  2084. return [["M", 0, 0]];
  2085. }
  2086. var res = [],
  2087. x = 0,
  2088. y = 0,
  2089. mx = 0,
  2090. my = 0,
  2091. start = 0;
  2092. if (pathArray[0][0] == "M") {
  2093. x = +pathArray[0][1];
  2094. y = +pathArray[0][2];
  2095. mx = x;
  2096. my = y;
  2097. start++;
  2098. res[0] = ["M", x, y];
  2099. }
  2100. var crz = pathArray.length == 3 && pathArray[0][0] == "M" && pathArray[1][0].toUpperCase() == "R" && pathArray[2][0].toUpperCase() == "Z";
  2101. for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) {
  2102. res.push(r = []);
  2103. pa = pathArray[i];
  2104. if (pa[0] != upperCase.call(pa[0])) {
  2105. r[0] = upperCase.call(pa[0]);
  2106. switch (r[0]) {
  2107. case "A":
  2108. r[1] = pa[1];
  2109. r[2] = pa[2];
  2110. r[3] = pa[3];
  2111. r[4] = pa[4];
  2112. r[5] = pa[5];
  2113. r[6] = +(pa[6] + x);
  2114. r[7] = +(pa[7] + y);
  2115. break;
  2116. case "V":
  2117. r[1] = +pa[1] + y;
  2118. break;
  2119. case "H":
  2120. r[1] = +pa[1] + x;
  2121. break;
  2122. case "R":
  2123. var dots = [x, y][concat](pa.slice(1));
  2124. for (var j = 2, jj = dots.length; j < jj; j++) {
  2125. dots[j] = +dots[j] + x;
  2126. dots[++j] = +dots[j] + y;
  2127. }
  2128. res.pop();
  2129. res = res[concat](catmullRom2bezier(dots, crz));
  2130. break;
  2131. case "M":
  2132. mx = +pa[1] + x;
  2133. my = +pa[2] + y;
  2134. default:
  2135. for (j = 1, jj = pa.length; j < jj; j++) {
  2136. r[j] = +pa[j] + ((j % 2) ? x : y);
  2137. }
  2138. }
  2139. } else if (pa[0] == "R") {
  2140. dots = [x, y][concat](pa.slice(1));
  2141. res.pop();
  2142. res = res[concat](catmullRom2bezier(dots, crz));
  2143. r = ["R"][concat](pa.slice(-2));
  2144. } else {
  2145. for (var k = 0, kk = pa.length; k < kk; k++) {
  2146. r[k] = pa[k];
  2147. }
  2148. }
  2149. switch (r[0]) {
  2150. case "Z":
  2151. x = mx;
  2152. y = my;
  2153. break;
  2154. case "H":
  2155. x = r[1];
  2156. break;
  2157. case "V":
  2158. y = r[1];
  2159. break;
  2160. case "M":
  2161. mx = r[r.length - 2];
  2162. my = r[r.length - 1];
  2163. default:
  2164. x = r[r.length - 2];
  2165. y = r[r.length - 1];
  2166. }
  2167. }
  2168. res.toString = R._path2string;
  2169. pth.abs = pathClone(res);
  2170. return res;
  2171. },
  2172. l2c = function (x1, y1, x2, y2) {
  2173. return [x1, y1, x2, y2, x2, y2];
  2174. },
  2175. q2c = function (x1, y1, ax, ay, x2, y2) {
  2176. var _13 = 1 / 3,
  2177. _23 = 2 / 3;
  2178. return [
  2179. _13 * x1 + _23 * ax,
  2180. _13 * y1 + _23 * ay,
  2181. _13 * x2 + _23 * ax,
  2182. _13 * y2 + _23 * ay,
  2183. x2,
  2184. y2
  2185. ];
  2186. },
  2187. a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
  2188. // for more information of where this math came from visit:
  2189. // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
  2190. var _120 = PI * 120 / 180,
  2191. rad = PI / 180 * (+angle || 0),
  2192. res = [],
  2193. xy,
  2194. rotate = cacher(function (x, y, rad) {
  2195. var X = x * math.cos(rad) - y * math.sin(rad),
  2196. Y = x * math.sin(rad) + y * math.cos(rad);
  2197. return {x: X, y: Y};
  2198. });
  2199. if (!recursive) {
  2200. xy = rotate(x1, y1, -rad);
  2201. x1 = xy.x;
  2202. y1 = xy.y;
  2203. xy = rotate(x2, y2, -rad);
  2204. x2 = xy.x;
  2205. y2 = xy.y;
  2206. var cos = math.cos(PI / 180 * angle),
  2207. sin = math.sin(PI / 180 * angle),
  2208. x = (x1 - x2) / 2,
  2209. y = (y1 - y2) / 2;
  2210. var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
  2211. if (h > 1) {
  2212. h = math.sqrt(h);
  2213. rx = h * rx;
  2214. ry = h * ry;
  2215. }
  2216. var rx2 = rx * rx,
  2217. ry2 = ry * ry,
  2218. k = (large_arc_flag == sweep_flag ? -1 : 1) *
  2219. math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
  2220. cx = k * rx * y / ry + (x1 + x2) / 2,
  2221. cy = k * -ry * x / rx + (y1 + y2) / 2,
  2222. f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
  2223. f2 = math.asin(((y2 - cy) / ry).toFixed(9));
  2224. f1 = x1 < cx ? PI - f1 : f1;
  2225. f2 = x2 < cx ? PI - f2 : f2;
  2226. f1 < 0 && (f1 = PI * 2 + f1);
  2227. f2 < 0 && (f2 = PI * 2 + f2);
  2228. if (sweep_flag && f1 > f2) {
  2229. f1 = f1 - PI * 2;
  2230. }
  2231. if (!sweep_flag && f2 > f1) {
  2232. f2 = f2 - PI * 2;
  2233. }
  2234. } else {
  2235. f1 = recursive[0];
  2236. f2 = recursive[1];
  2237. cx = recursive[2];
  2238. cy = recursive[3];
  2239. }
  2240. var df = f2 - f1;
  2241. if (abs(df) > _120) {
  2242. var f2old = f2,
  2243. x2old = x2,
  2244. y2old = y2;
  2245. f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
  2246. x2 = cx + rx * math.cos(f2);
  2247. y2 = cy + ry * math.sin(f2);
  2248. res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
  2249. }
  2250. df = f2 - f1;
  2251. var c1 = math.cos(f1),
  2252. s1 = math.sin(f1),
  2253. c2 = math.cos(f2),
  2254. s2 = math.sin(f2),
  2255. t = math.tan(df / 4),
  2256. hx = 4 / 3 * rx * t,
  2257. hy = 4 / 3 * ry * t,
  2258. m1 = [x1, y1],
  2259. m2 = [x1 + hx * s1, y1 - hy * c1],
  2260. m3 = [x2 + hx * s2, y2 - hy * c2],
  2261. m4 = [x2, y2];
  2262. m2[0] = 2 * m1[0] - m2[0];
  2263. m2[1] = 2 * m1[1] - m2[1];
  2264. if (recursive) {
  2265. return [m2, m3, m4][concat](res);
  2266. } else {
  2267. res = [m2, m3, m4][concat](res).join()[split](",");
  2268. var newres = [];
  2269. for (var i = 0, ii = res.length; i < ii; i++) {
  2270. newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
  2271. }
  2272. return newres;
  2273. }
  2274. },
  2275. findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  2276. var t1 = 1 - t;
  2277. return {
  2278. x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
  2279. y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
  2280. };
  2281. },
  2282. curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
  2283. var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
  2284. b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
  2285. c = p1x - c1x,
  2286. t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
  2287. t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
  2288. y = [p1y, p2y],
  2289. x = [p1x, p2x],
  2290. dot;
  2291. abs(t1) > "1e12" && (t1 = .5);
  2292. abs(t2) > "1e12" && (t2 = .5);
  2293. if (t1 > 0 && t1 < 1) {
  2294. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
  2295. x.push(dot.x);
  2296. y.push(dot.y);
  2297. }
  2298. if (t2 > 0 && t2 < 1) {
  2299. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
  2300. x.push(dot.x);
  2301. y.push(dot.y);
  2302. }
  2303. a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
  2304. b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
  2305. c = p1y - c1y;
  2306. t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
  2307. t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
  2308. abs(t1) > "1e12" && (t1 = .5);
  2309. abs(t2) > "1e12" && (t2 = .5);
  2310. if (t1 > 0 && t1 < 1) {
  2311. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
  2312. x.push(dot.x);
  2313. y.push(dot.y);
  2314. }
  2315. if (t2 > 0 && t2 < 1) {
  2316. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
  2317. x.push(dot.x);
  2318. y.push(dot.y);
  2319. }
  2320. return {
  2321. min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
  2322. max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
  2323. };
  2324. }),
  2325. path2curve = R._path2curve = cacher(function (path, path2) {
  2326. var pth = !path2 && paths(path);
  2327. if (!path2 && pth.curve) {
  2328. return pathClone(pth.curve);
  2329. }
  2330. var p = pathToAbsolute(path),
  2331. p2 = path2 && pathToAbsolute(path2),
  2332. attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
  2333. attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
  2334. processPath = function (path, d, pcom) {
  2335. var nx, ny;
  2336. if (!path) {
  2337. return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
  2338. }
  2339. !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
  2340. switch (path[0]) {
  2341. case "M":
  2342. d.X = path[1];
  2343. d.Y = path[2];
  2344. break;
  2345. case "A":
  2346. path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
  2347. break;
  2348. case "S":
  2349. if (pcom == "C" || pcom == "S") { // In "S" case we have to take into account, if the previous command is C/S.
  2350. nx = d.x * 2 - d.bx; // And reflect the previous
  2351. ny = d.y * 2 - d.by; // command's control point relative to the current point.
  2352. }
  2353. else { // or some else or nothing
  2354. nx = d.x;
  2355. ny = d.y;
  2356. }
  2357. path = ["C", nx, ny][concat](path.slice(1));
  2358. break;
  2359. case "T":
  2360. if (pcom == "Q" || pcom == "T") { // In "T" case we have to take into account, if the previous command is Q/T.
  2361. d.qx = d.x * 2 - d.qx; // And make a reflection similar
  2362. d.qy = d.y * 2 - d.qy; // to case "S".
  2363. }
  2364. else { // or something else or nothing
  2365. d.qx = d.x;
  2366. d.qy = d.y;
  2367. }
  2368. path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
  2369. break;
  2370. case "Q":
  2371. d.qx = path[1];
  2372. d.qy = path[2];
  2373. path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
  2374. break;
  2375. case "L":
  2376. path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
  2377. break;
  2378. case "H":
  2379. path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
  2380. break;
  2381. case "V":
  2382. path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
  2383. break;
  2384. case "Z":
  2385. path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
  2386. break;
  2387. }
  2388. return path;
  2389. },
  2390. fixArc = function (pp, i) {
  2391. if (pp[i].length > 7) {
  2392. pp[i].shift();
  2393. var pi = pp[i];
  2394. while (pi.length) {
  2395. pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
  2396. }
  2397. pp.splice(i, 1);
  2398. ii = mmax(p.length, p2 && p2.length || 0);
  2399. }
  2400. },
  2401. fixM = function (path1, path2, a1, a2, i) {
  2402. if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
  2403. path2.splice(i, 0, ["M", a2.x, a2.y]);
  2404. a1.bx = 0;
  2405. a1.by = 0;
  2406. a1.x = path1[i][1];
  2407. a1.y = path1[i][2];
  2408. ii = mmax(p.length, p2 && p2.length || 0);
  2409. }
  2410. };
  2411. for (var i = 0, ii = mmax(p.length, p2 && p2.length || 0); i < ii; i++) {
  2412. p[i] = processPath(p[i], attrs);
  2413. fixArc(p, i);
  2414. p2 && (p2[i] = processPath(p2[i], attrs2));
  2415. p2 && fixArc(p2, i);
  2416. fixM(p, p2, attrs, attrs2, i);
  2417. fixM(p2, p, attrs2, attrs, i);
  2418. var seg = p[i],
  2419. seg2 = p2 && p2[i],
  2420. seglen = seg.length,
  2421. seg2len = p2 && seg2.length;
  2422. attrs.x = seg[seglen - 2];
  2423. attrs.y = seg[seglen - 1];
  2424. attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
  2425. attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
  2426. attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
  2427. attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
  2428. attrs2.x = p2 && seg2[seg2len - 2];
  2429. attrs2.y = p2 && seg2[seg2len - 1];
  2430. }
  2431. if (!p2) {
  2432. pth.curve = pathClone(p);
  2433. }
  2434. return p2 ? [p, p2] : p;
  2435. }, null, pathClone),
  2436. parseDots = R._parseDots = cacher(function (gradient) {
  2437. var dots = [];
  2438. for (var i = 0, ii = gradient.length; i < ii; i++) {
  2439. var dot = {},
  2440. par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
  2441. dot.color = R.getRGB(par[1]);
  2442. if (dot.color.error) {
  2443. return null;
  2444. }
  2445. dot.color = dot.color.hex;
  2446. par[2] && (dot.offset = par[2] + "%");
  2447. dots.push(dot);
  2448. }
  2449. for (i = 1, ii = dots.length - 1; i < ii; i++) {
  2450. if (!dots[i].offset) {
  2451. var start = toFloat(dots[i - 1].offset || 0),
  2452. end = 0;
  2453. for (var j = i + 1; j < ii; j++) {
  2454. if (dots[j].offset) {
  2455. end = dots[j].offset;
  2456. break;
  2457. }
  2458. }
  2459. if (!end) {
  2460. end = 100;
  2461. j = ii;
  2462. }
  2463. end = toFloat(end);
  2464. var d = (end - start) / (j - i + 1);
  2465. for (; i < j; i++) {
  2466. start += d;
  2467. dots[i].offset = start + "%";
  2468. }
  2469. }
  2470. }
  2471. return dots;
  2472. }),
  2473. tear = R._tear = function (el, paper) {
  2474. el == paper.top && (paper.top = el.prev);
  2475. el == paper.bottom && (paper.bottom = el.next);
  2476. el.next && (el.next.prev = el.prev);
  2477. el.prev && (el.prev.next = el.next);
  2478. },
  2479. tofront = R._tofront = function (el, paper) {
  2480. if (paper.top === el) {
  2481. return;
  2482. }
  2483. tear(el, paper);
  2484. el.next = null;
  2485. el.prev = paper.top;
  2486. paper.top.next = el;
  2487. paper.top = el;
  2488. },
  2489. toback = R._toback = function (el, paper) {
  2490. if (paper.bottom === el) {
  2491. return;
  2492. }
  2493. tear(el, paper);
  2494. el.next = paper.bottom;
  2495. el.prev = null;
  2496. paper.bottom.prev = el;
  2497. paper.bottom = el;
  2498. },
  2499. insertafter = R._insertafter = function (el, el2, paper) {
  2500. tear(el, paper);
  2501. el2 == paper.top && (paper.top = el);
  2502. el2.next && (el2.next.prev = el);
  2503. el.next = el2.next;
  2504. el.prev = el2;
  2505. el2.next = el;
  2506. },
  2507. insertbefore = R._insertbefore = function (el, el2, paper) {
  2508. tear(el, paper);
  2509. el2 == paper.bottom && (paper.bottom = el);
  2510. el2.prev && (el2.prev.next = el);
  2511. el.prev = el2.prev;
  2512. el2.prev = el;
  2513. el.next = el2;
  2514. },
  2515. /*\
  2516. * Raphael.toMatrix
  2517. [ method ]
  2518. **
  2519. * Utility method
  2520. **
  2521. * Returns matrix of transformations applied to a given path
  2522. > Parameters
  2523. - path (string) path string
  2524. - transform (string|array) transformation string
  2525. = (object) @Matrix
  2526. \*/
  2527. toMatrix = R.toMatrix = function (path, transform) {
  2528. var bb = pathDimensions(path),
  2529. el = {
  2530. _: {
  2531. transform: E
  2532. },
  2533. getBBox: function () {
  2534. return bb;
  2535. }
  2536. };
  2537. extractTransform(el, transform);
  2538. return el.matrix;
  2539. },
  2540. /*\
  2541. * Raphael.transformPath
  2542. [ method ]
  2543. **
  2544. * Utility method
  2545. **
  2546. * Returns path transformed by a given transformation
  2547. > Parameters
  2548. - path (string) path string
  2549. - transform (string|array) transformation string
  2550. = (string) path
  2551. \*/
  2552. transformPath = R.transformPath = function (path, transform) {
  2553. return mapPath(path, toMatrix(path, transform));
  2554. },
  2555. extractTransform = R._extractTransform = function (el, tstr) {
  2556. if (tstr == null) {
  2557. return el._.transform;
  2558. }
  2559. tstr = Str(tstr).replace(/\.{3}|\u2026/g, el._.transform || E);
  2560. var tdata = R.parseTransformString(tstr),
  2561. deg = 0,
  2562. dx = 0,
  2563. dy = 0,
  2564. sx = 1,
  2565. sy = 1,
  2566. _ = el._,
  2567. m = new Matrix;
  2568. _.transform = tdata || [];
  2569. if (tdata) {
  2570. for (var i = 0, ii = tdata.length; i < ii; i++) {
  2571. var t = tdata[i],
  2572. tlen = t.length,
  2573. command = Str(t[0]).toLowerCase(),
  2574. absolute = t[0] != command,
  2575. inver = absolute ? m.invert() : 0,
  2576. x1,
  2577. y1,
  2578. x2,
  2579. y2,
  2580. bb;
  2581. if (command == "t" && tlen == 3) {
  2582. if (absolute) {
  2583. x1 = inver.x(0, 0);
  2584. y1 = inver.y(0, 0);
  2585. x2 = inver.x(t[1], t[2]);
  2586. y2 = inver.y(t[1], t[2]);
  2587. m.translate(x2 - x1, y2 - y1);
  2588. } else {
  2589. m.translate(t[1], t[2]);
  2590. }
  2591. } else if (command == "r") {
  2592. if (tlen == 2) {
  2593. bb = bb || el.getBBox(1);
  2594. m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2);
  2595. deg += t[1];
  2596. } else if (tlen == 4) {
  2597. if (absolute) {
  2598. x2 = inver.x(t[2], t[3]);
  2599. y2 = inver.y(t[2], t[3]);
  2600. m.rotate(t[1], x2, y2);
  2601. } else {
  2602. m.rotate(t[1], t[2], t[3]);
  2603. }
  2604. deg += t[1];
  2605. }
  2606. } else if (command == "s") {
  2607. if (tlen == 2 || tlen == 3) {
  2608. bb = bb || el.getBBox(1);
  2609. m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2);
  2610. sx *= t[1];
  2611. sy *= t[tlen - 1];
  2612. } else if (tlen == 5) {
  2613. if (absolute) {
  2614. x2 = inver.x(t[3], t[4]);
  2615. y2 = inver.y(t[3], t[4]);
  2616. m.scale(t[1], t[2], x2, y2);
  2617. } else {
  2618. m.scale(t[1], t[2], t[3], t[4]);
  2619. }
  2620. sx *= t[1];
  2621. sy *= t[2];
  2622. }
  2623. } else if (command == "m" && tlen == 7) {
  2624. m.add(t[1], t[2], t[3], t[4], t[5], t[6]);
  2625. }
  2626. _.dirtyT = 1;
  2627. el.matrix = m;
  2628. }
  2629. }
  2630. /*\
  2631. * Element.matrix
  2632. [ property (object) ]
  2633. **
  2634. * Keeps @Matrix object, which represents element transformation
  2635. \*/
  2636. el.matrix = m;
  2637. _.sx = sx;
  2638. _.sy = sy;
  2639. _.deg = deg;
  2640. _.dx = dx = m.e;
  2641. _.dy = dy = m.f;
  2642. if (sx == 1 && sy == 1 && !deg && _.bbox) {
  2643. _.bbox.x += +dx;
  2644. _.bbox.y += +dy;
  2645. } else {
  2646. _.dirtyT = 1;
  2647. }
  2648. },
  2649. getEmpty = function (item) {
  2650. var l = item[0];
  2651. switch (l.toLowerCase()) {
  2652. case "t": return [l, 0, 0];
  2653. case "m": return [l, 1, 0, 0, 1, 0, 0];
  2654. case "r": if (item.length == 4) {
  2655. return [l, 0, item[2], item[3]];
  2656. } else {
  2657. return [l, 0];
  2658. }
  2659. case "s": if (item.length == 5) {
  2660. return [l, 1, 1, item[3], item[4]];
  2661. } else if (item.length == 3) {
  2662. return [l, 1, 1];
  2663. } else {
  2664. return [l, 1];
  2665. }
  2666. }
  2667. },
  2668. equaliseTransform = R._equaliseTransform = function (t1, t2) {
  2669. t2 = Str(t2).replace(/\.{3}|\u2026/g, t1);
  2670. t1 = R.parseTransformString(t1) || [];
  2671. t2 = R.parseTransformString(t2) || [];
  2672. var maxlength = mmax(t1.length, t2.length),
  2673. from = [],
  2674. to = [],
  2675. i = 0, j, jj,
  2676. tt1, tt2;
  2677. for (; i < maxlength; i++) {
  2678. tt1 = t1[i] || getEmpty(t2[i]);
  2679. tt2 = t2[i] || getEmpty(tt1);
  2680. if ((tt1[0] != tt2[0]) ||
  2681. (tt1[0].toLowerCase() == "r" && (tt1[2] != tt2[2] || tt1[3] != tt2[3])) ||
  2682. (tt1[0].toLowerCase() == "s" && (tt1[3] != tt2[3] || tt1[4] != tt2[4]))
  2683. ) {
  2684. return;
  2685. }
  2686. from[i] = [];
  2687. to[i] = [];
  2688. for (j = 0, jj = mmax(tt1.length, tt2.length); j < jj; j++) {
  2689. j in tt1 && (from[i][j] = tt1[j]);
  2690. j in tt2 && (to[i][j] = tt2[j]);
  2691. }
  2692. }
  2693. return {
  2694. from: from,
  2695. to: to
  2696. };
  2697. };
  2698. R._getContainer = function (x, y, w, h) {
  2699. var container;
  2700. container = h == null && !R.is(x, "object") ? g.doc.getElementById(x) : x;
  2701. if (container == null) {
  2702. return;
  2703. }
  2704. if (container.tagName) {
  2705. if (y == null) {
  2706. return {
  2707. container: container,
  2708. width: container.style.pixelWidth || container.offsetWidth,
  2709. height: container.style.pixelHeight || container.offsetHeight
  2710. };
  2711. } else {
  2712. return {
  2713. container: container,
  2714. width: y,
  2715. height: w
  2716. };
  2717. }
  2718. }
  2719. return {
  2720. container: 1,
  2721. x: x,
  2722. y: y,
  2723. width: w,
  2724. height: h
  2725. };
  2726. };
  2727. /*\
  2728. * Raphael.pathToRelative
  2729. [ method ]
  2730. **
  2731. * Utility method
  2732. **
  2733. * Converts path to relative form
  2734. > Parameters
  2735. - pathString (string|array) path string or array of segments
  2736. = (array) array of segments.
  2737. \*/
  2738. R.pathToRelative = pathToRelative;
  2739. R._engine = {};
  2740. /*\
  2741. * Raphael.path2curve
  2742. [ method ]
  2743. **
  2744. * Utility method
  2745. **
  2746. * Converts path to a new path where all segments are cubic bezier curves.
  2747. > Parameters
  2748. - pathString (string|array) path string or array of segments
  2749. = (array) array of segments.
  2750. \*/
  2751. R.path2curve = path2curve;
  2752. /*\
  2753. * Raphael.matrix
  2754. [ method ]
  2755. **
  2756. * Utility method
  2757. **
  2758. * Returns matrix based on given parameters.
  2759. > Parameters
  2760. - a (number)
  2761. - b (number)
  2762. - c (number)
  2763. - d (number)
  2764. - e (number)
  2765. - f (number)
  2766. = (object) @Matrix
  2767. \*/
  2768. R.matrix = function (a, b, c, d, e, f) {
  2769. return new Matrix(a, b, c, d, e, f);
  2770. };
  2771. function Matrix(a, b, c, d, e, f) {
  2772. if (a != null) {
  2773. this.a = +a;
  2774. this.b = +b;
  2775. this.c = +c;
  2776. this.d = +d;
  2777. this.e = +e;
  2778. this.f = +f;
  2779. } else {
  2780. this.a = 1;
  2781. this.b = 0;
  2782. this.c = 0;
  2783. this.d = 1;
  2784. this.e = 0;
  2785. this.f = 0;
  2786. }
  2787. }
  2788. (function (matrixproto) {
  2789. /*\
  2790. * Matrix.add
  2791. [ method ]
  2792. **
  2793. * Adds given matrix to existing one.
  2794. > Parameters
  2795. - a (number)
  2796. - b (number)
  2797. - c (number)
  2798. - d (number)
  2799. - e (number)
  2800. - f (number)
  2801. or
  2802. - matrix (object) @Matrix
  2803. \*/
  2804. matrixproto.add = function (a, b, c, d, e, f) {
  2805. var out = [[], [], []],
  2806. m = [[this.a, this.c, this.e], [this.b, this.d, this.f], [0, 0, 1]],
  2807. matrix = [[a, c, e], [b, d, f], [0, 0, 1]],
  2808. x, y, z, res;
  2809. if (a && a instanceof Matrix) {
  2810. matrix = [[a.a, a.c, a.e], [a.b, a.d, a.f], [0, 0, 1]];
  2811. }
  2812. for (x = 0; x < 3; x++) {
  2813. for (y = 0; y < 3; y++) {
  2814. res = 0;
  2815. for (z = 0; z < 3; z++) {
  2816. res += m[x][z] * matrix[z][y];
  2817. }
  2818. out[x][y] = res;
  2819. }
  2820. }
  2821. this.a = out[0][0];
  2822. this.b = out[1][0];
  2823. this.c = out[0][1];
  2824. this.d = out[1][1];
  2825. this.e = out[0][2];
  2826. this.f = out[1][2];
  2827. };
  2828. /*\
  2829. * Matrix.invert
  2830. [ method ]
  2831. **
  2832. * Returns inverted version of the matrix
  2833. = (object) @Matrix
  2834. \*/
  2835. matrixproto.invert = function () {
  2836. var me = this,
  2837. x = me.a * me.d - me.b * me.c;
  2838. 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);
  2839. };
  2840. /*\
  2841. * Matrix.clone
  2842. [ method ]
  2843. **
  2844. * Returns copy of the matrix
  2845. = (object) @Matrix
  2846. \*/
  2847. matrixproto.clone = function () {
  2848. return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
  2849. };
  2850. /*\
  2851. * Matrix.translate
  2852. [ method ]
  2853. **
  2854. * Translate the matrix
  2855. > Parameters
  2856. - x (number)
  2857. - y (number)
  2858. \*/
  2859. matrixproto.translate = function (x, y) {
  2860. this.add(1, 0, 0, 1, x, y);
  2861. };
  2862. /*\
  2863. * Matrix.scale
  2864. [ method ]
  2865. **
  2866. * Scales the matrix
  2867. > Parameters
  2868. - x (number)
  2869. - y (number) #optional
  2870. - cx (number) #optional
  2871. - cy (number) #optional
  2872. \*/
  2873. matrixproto.scale = function (x, y, cx, cy) {
  2874. y == null && (y = x);
  2875. (cx || cy) && this.add(1, 0, 0, 1, cx, cy);
  2876. this.add(x, 0, 0, y, 0, 0);
  2877. (cx || cy) && this.add(1, 0, 0, 1, -cx, -cy);
  2878. };
  2879. /*\
  2880. * Matrix.rotate
  2881. [ method ]
  2882. **
  2883. * Rotates the matrix
  2884. > Parameters
  2885. - a (number)
  2886. - x (number)
  2887. - y (number)
  2888. \*/
  2889. matrixproto.rotate = function (a, x, y) {
  2890. a = R.rad(a);
  2891. x = x || 0;
  2892. y = y || 0;
  2893. var cos = +math.cos(a).toFixed(9),
  2894. sin = +math.sin(a).toFixed(9);
  2895. this.add(cos, sin, -sin, cos, x, y);
  2896. this.add(1, 0, 0, 1, -x, -y);
  2897. };
  2898. /*\
  2899. * Matrix.x
  2900. [ method ]
  2901. **
  2902. * Return x coordinate for given point after transformation described by the matrix. See also @Matrix.y
  2903. > Parameters
  2904. - x (number)
  2905. - y (number)
  2906. = (number) x
  2907. \*/
  2908. matrixproto.x = function (x, y) {
  2909. return x * this.a + y * this.c + this.e;
  2910. };
  2911. /*\
  2912. * Matrix.y
  2913. [ method ]
  2914. **
  2915. * Return y coordinate for given point after transformation described by the matrix. See also @Matrix.x
  2916. > Parameters
  2917. - x (number)
  2918. - y (number)
  2919. = (number) y
  2920. \*/
  2921. matrixproto.y = function (x, y) {
  2922. return x * this.b + y * this.d + this.f;
  2923. };
  2924. matrixproto.get = function (i) {
  2925. return +this[Str.fromCharCode(97 + i)].toFixed(4);
  2926. };
  2927. matrixproto.toString = function () {
  2928. return R.svg ?
  2929. "matrix(" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)].join() + ")" :
  2930. [this.get(0), this.get(2), this.get(1), this.get(3), 0, 0].join();
  2931. };
  2932. matrixproto.toFilter = function () {
  2933. return "progid:DXImageTransform.Microsoft.Matrix(M11=" + this.get(0) +
  2934. ", M12=" + this.get(2) + ", M21=" + this.get(1) + ", M22=" + this.get(3) +
  2935. ", Dx=" + this.get(4) + ", Dy=" + this.get(5) + ", sizingmethod='auto expand')";
  2936. };
  2937. matrixproto.offset = function () {
  2938. return [this.e.toFixed(4), this.f.toFixed(4)];
  2939. };
  2940. function norm(a) {
  2941. return a[0] * a[0] + a[1] * a[1];
  2942. }
  2943. function normalize(a) {
  2944. var mag = math.sqrt(norm(a));
  2945. a[0] && (a[0] /= mag);
  2946. a[1] && (a[1] /= mag);
  2947. }
  2948. /*\
  2949. * Matrix.split
  2950. [ method ]
  2951. **
  2952. * Splits matrix into primitive transformations
  2953. = (object) in format:
  2954. o dx (number) translation by x
  2955. o dy (number) translation by y
  2956. o scalex (number) scale by x
  2957. o scaley (number) scale by y
  2958. o shear (number) shear
  2959. o rotate (number) rotation in deg
  2960. o isSimple (boolean) could it be represented via simple transformations
  2961. \*/
  2962. matrixproto.split = function () {
  2963. var out = {};
  2964. // translation
  2965. out.dx = this.e;
  2966. out.dy = this.f;
  2967. // scale and shear
  2968. var row = [[this.a, this.c], [this.b, this.d]];
  2969. out.scalex = math.sqrt(norm(row[0]));
  2970. normalize(row[0]);
  2971. out.shear = row[0][0] * row[1][0] + row[0][1] * row[1][1];
  2972. row[1] = [row[1][0] - row[0][0] * out.shear, row[1][1] - row[0][1] * out.shear];
  2973. out.scaley = math.sqrt(norm(row[1]));
  2974. normalize(row[1]);
  2975. out.shear /= out.scaley;
  2976. // rotation
  2977. var sin = -row[0][1],
  2978. cos = row[1][1];
  2979. if (cos < 0) {
  2980. out.rotate = R.deg(math.acos(cos));
  2981. if (sin < 0) {
  2982. out.rotate = 360 - out.rotate;
  2983. }
  2984. } else {
  2985. out.rotate = R.deg(math.asin(sin));
  2986. }
  2987. out.isSimple = !+out.shear.toFixed(9) && (out.scalex.toFixed(9) == out.scaley.toFixed(9) || !out.rotate);
  2988. out.isSuperSimple = !+out.shear.toFixed(9) && out.scalex.toFixed(9) == out.scaley.toFixed(9) && !out.rotate;
  2989. out.noRotation = !+out.shear.toFixed(9) && !out.rotate;
  2990. return out;
  2991. };
  2992. /*\
  2993. * Matrix.toTransformString
  2994. [ method ]
  2995. **
  2996. * Return transform string that represents given matrix
  2997. = (string) transform string
  2998. \*/
  2999. matrixproto.toTransformString = function (shorter) {
  3000. var s = shorter || this[split]();
  3001. if (s.isSimple) {
  3002. s.scalex = +s.scalex.toFixed(4);
  3003. s.scaley = +s.scaley.toFixed(4);
  3004. s.rotate = +s.rotate.toFixed(4);
  3005. return (s.dx || s.dy ? "t" + [s.dx, s.dy] : E) +
  3006. (s.scalex != 1 || s.scaley != 1 ? "s" + [s.scalex, s.scaley, 0, 0] : E) +
  3007. (s.rotate ? "r" + [s.rotate, 0, 0] : E);
  3008. } else {
  3009. return "m" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)];
  3010. }
  3011. };
  3012. })(Matrix.prototype);
  3013. // WebKit rendering bug workaround method
  3014. var version = navigator.userAgent.match(/Version\/(.*?)\s/) || navigator.userAgent.match(/Chrome\/(\d+)/);
  3015. if ((navigator.vendor == "Apple Computer, Inc.") && (version && version[1] < 4 || navigator.platform.slice(0, 2) == "iP") ||
  3016. (navigator.vendor == "Google Inc." && version && version[1] < 8)) {
  3017. /*\
  3018. * Paper.safari
  3019. [ method ]
  3020. **
  3021. * There is an inconvenient rendering bug in Safari (WebKit):
  3022. * sometimes the rendering should be forced.
  3023. * This method should help with dealing with this bug.
  3024. \*/
  3025. paperproto.safari = function () {
  3026. var rect = this.rect(-99, -99, this.width + 99, this.height + 99).attr({stroke: "none"});
  3027. setTimeout(function () {rect.remove();});
  3028. };
  3029. } else {
  3030. paperproto.safari = fun;
  3031. }
  3032. var preventDefault = function () {
  3033. this.returnValue = false;
  3034. },
  3035. preventTouch = function () {
  3036. return this.originalEvent.preventDefault();
  3037. },
  3038. stopPropagation = function () {
  3039. this.cancelBubble = true;
  3040. },
  3041. stopTouch = function () {
  3042. return this.originalEvent.stopPropagation();
  3043. },
  3044. getEventPosition = function (e) {
  3045. var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  3046. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft;
  3047. return {
  3048. x: e.clientX + scrollX,
  3049. y: e.clientY + scrollY
  3050. };
  3051. },
  3052. addEvent = (function () {
  3053. if (g.doc.addEventListener) {
  3054. return function (obj, type, fn, element) {
  3055. var f = function (e) {
  3056. var pos = getEventPosition(e);
  3057. return fn.call(element, e, pos.x, pos.y);
  3058. };
  3059. obj.addEventListener(type, f, false);
  3060. if (supportsTouch && touchMap[type]) {
  3061. var _f = function (e) {
  3062. var pos = getEventPosition(e),
  3063. olde = e;
  3064. for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
  3065. if (e.targetTouches[i].target == obj) {
  3066. e = e.targetTouches[i];
  3067. e.originalEvent = olde;
  3068. e.preventDefault = preventTouch;
  3069. e.stopPropagation = stopTouch;
  3070. break;
  3071. }
  3072. }
  3073. return fn.call(element, e, pos.x, pos.y);
  3074. };
  3075. obj.addEventListener(touchMap[type], _f, false);
  3076. }
  3077. return function () {
  3078. obj.removeEventListener(type, f, false);
  3079. if (supportsTouch && touchMap[type])
  3080. obj.removeEventListener(touchMap[type], f, false);
  3081. return true;
  3082. };
  3083. };
  3084. } else if (g.doc.attachEvent) {
  3085. return function (obj, type, fn, element) {
  3086. var f = function (e) {
  3087. e = e || g.win.event;
  3088. var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  3089. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
  3090. x = e.clientX + scrollX,
  3091. y = e.clientY + scrollY;
  3092. e.preventDefault = e.preventDefault || preventDefault;
  3093. e.stopPropagation = e.stopPropagation || stopPropagation;
  3094. return fn.call(element, e, x, y);
  3095. };
  3096. obj.attachEvent("on" + type, f);
  3097. var detacher = function () {
  3098. obj.detachEvent("on" + type, f);
  3099. return true;
  3100. };
  3101. return detacher;
  3102. };
  3103. }
  3104. })(),
  3105. drag = [],
  3106. dragMove = function (e) {
  3107. var x = e.clientX,
  3108. y = e.clientY,
  3109. scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  3110. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
  3111. dragi,
  3112. j = drag.length;
  3113. while (j--) {
  3114. dragi = drag[j];
  3115. if (supportsTouch && e.touches) {
  3116. var i = e.touches.length,
  3117. touch;
  3118. while (i--) {
  3119. touch = e.touches[i];
  3120. if (touch.identifier == dragi.el._drag.id) {
  3121. x = touch.clientX;
  3122. y = touch.clientY;
  3123. (e.originalEvent ? e.originalEvent : e).preventDefault();
  3124. break;
  3125. }
  3126. }
  3127. } else {
  3128. e.preventDefault();
  3129. }
  3130. var node = dragi.el.node,
  3131. o,
  3132. next = node.nextSibling,
  3133. parent = node.parentNode,
  3134. display = node.style.display;
  3135. g.win.opera && parent.removeChild(node);
  3136. node.style.display = "none";
  3137. o = dragi.el.paper.getElementByPoint(x, y);
  3138. node.style.display = display;
  3139. g.win.opera && (next ? parent.insertBefore(node, next) : parent.appendChild(node));
  3140. o && eve("raphael.drag.over." + dragi.el.id, dragi.el, o);
  3141. x += scrollX;
  3142. y += scrollY;
  3143. eve("raphael.drag.move." + dragi.el.id, dragi.move_scope || dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y, e);
  3144. }
  3145. },
  3146. dragUp = function (e) {
  3147. R.unmousemove(dragMove).unmouseup(dragUp);
  3148. var i = drag.length,
  3149. dragi;
  3150. while (i--) {
  3151. dragi = drag[i];
  3152. dragi.el._drag = {};
  3153. eve("raphael.drag.end." + dragi.el.id, dragi.end_scope || dragi.start_scope || dragi.move_scope || dragi.el, e);
  3154. }
  3155. drag = [];
  3156. },
  3157. /*\
  3158. * Raphael.el
  3159. [ property (object) ]
  3160. **
  3161. * You can add your own method to elements. This is usefull when you want to hack default functionality or
  3162. * want to wrap some common transformation or attributes in one method. In difference to canvas methods,
  3163. * you can redefine element method at any time. Expending element methods wouldn’t affect set.
  3164. > Usage
  3165. | Raphael.el.red = function () {
  3166. | this.attr({fill: "#f00"});
  3167. | };
  3168. | // then use it
  3169. | paper.circle(100, 100, 20).red();
  3170. \*/
  3171. elproto = R.el = {};
  3172. /*\
  3173. * Element.click
  3174. [ method ]
  3175. **
  3176. * Adds event handler for click for the element.
  3177. > Parameters
  3178. - handler (function) handler for the event
  3179. = (object) @Element
  3180. \*/
  3181. /*\
  3182. * Element.unclick
  3183. [ method ]
  3184. **
  3185. * Removes event handler for click for the element.
  3186. > Parameters
  3187. - handler (function) #optional handler for the event
  3188. = (object) @Element
  3189. \*/
  3190. /*\
  3191. * Element.dblclick
  3192. [ method ]
  3193. **
  3194. * Adds event handler for double click for the element.
  3195. > Parameters
  3196. - handler (function) handler for the event
  3197. = (object) @Element
  3198. \*/
  3199. /*\
  3200. * Element.undblclick
  3201. [ method ]
  3202. **
  3203. * Removes event handler for double click for the element.
  3204. > Parameters
  3205. - handler (function) #optional handler for the event
  3206. = (object) @Element
  3207. \*/
  3208. /*\
  3209. * Element.mousedown
  3210. [ method ]
  3211. **
  3212. * Adds event handler for mousedown for the element.
  3213. > Parameters
  3214. - handler (function) handler for the event
  3215. = (object) @Element
  3216. \*/
  3217. /*\
  3218. * Element.unmousedown
  3219. [ method ]
  3220. **
  3221. * Removes event handler for mousedown for the element.
  3222. > Parameters
  3223. - handler (function) #optional handler for the event
  3224. = (object) @Element
  3225. \*/
  3226. /*\
  3227. * Element.mousemove
  3228. [ method ]
  3229. **
  3230. * Adds event handler for mousemove for the element.
  3231. > Parameters
  3232. - handler (function) handler for the event
  3233. = (object) @Element
  3234. \*/
  3235. /*\
  3236. * Element.unmousemove
  3237. [ method ]
  3238. **
  3239. * Removes event handler for mousemove for the element.
  3240. > Parameters
  3241. - handler (function) #optional handler for the event
  3242. = (object) @Element
  3243. \*/
  3244. /*\
  3245. * Element.mouseout
  3246. [ method ]
  3247. **
  3248. * Adds event handler for mouseout for the element.
  3249. > Parameters
  3250. - handler (function) handler for the event
  3251. = (object) @Element
  3252. \*/
  3253. /*\
  3254. * Element.unmouseout
  3255. [ method ]
  3256. **
  3257. * Removes event handler for mouseout for the element.
  3258. > Parameters
  3259. - handler (function) #optional handler for the event
  3260. = (object) @Element
  3261. \*/
  3262. /*\
  3263. * Element.mouseover
  3264. [ method ]
  3265. **
  3266. * Adds event handler for mouseover for the element.
  3267. > Parameters
  3268. - handler (function) handler for the event
  3269. = (object) @Element
  3270. \*/
  3271. /*\
  3272. * Element.unmouseover
  3273. [ method ]
  3274. **
  3275. * Removes event handler for mouseover for the element.
  3276. > Parameters
  3277. - handler (function) #optional handler for the event
  3278. = (object) @Element
  3279. \*/
  3280. /*\
  3281. * Element.mouseup
  3282. [ method ]
  3283. **
  3284. * Adds event handler for mouseup for the element.
  3285. > Parameters
  3286. - handler (function) handler for the event
  3287. = (object) @Element
  3288. \*/
  3289. /*\
  3290. * Element.unmouseup
  3291. [ method ]
  3292. **
  3293. * Removes event handler for mouseup for the element.
  3294. > Parameters
  3295. - handler (function) #optional handler for the event
  3296. = (object) @Element
  3297. \*/
  3298. /*\
  3299. * Element.touchstart
  3300. [ method ]
  3301. **
  3302. * Adds event handler for touchstart for the element.
  3303. > Parameters
  3304. - handler (function) handler for the event
  3305. = (object) @Element
  3306. \*/
  3307. /*\
  3308. * Element.untouchstart
  3309. [ method ]
  3310. **
  3311. * Removes event handler for touchstart for the element.
  3312. > Parameters
  3313. - handler (function) #optional handler for the event
  3314. = (object) @Element
  3315. \*/
  3316. /*\
  3317. * Element.touchmove
  3318. [ method ]
  3319. **
  3320. * Adds event handler for touchmove for the element.
  3321. > Parameters
  3322. - handler (function) handler for the event
  3323. = (object) @Element
  3324. \*/
  3325. /*\
  3326. * Element.untouchmove
  3327. [ method ]
  3328. **
  3329. * Removes event handler for touchmove for the element.
  3330. > Parameters
  3331. - handler (function) #optional handler for the event
  3332. = (object) @Element
  3333. \*/
  3334. /*\
  3335. * Element.touchend
  3336. [ method ]
  3337. **
  3338. * Adds event handler for touchend for the element.
  3339. > Parameters
  3340. - handler (function) handler for the event
  3341. = (object) @Element
  3342. \*/
  3343. /*\
  3344. * Element.untouchend
  3345. [ method ]
  3346. **
  3347. * Removes event handler for touchend for the element.
  3348. > Parameters
  3349. - handler (function) #optional handler for the event
  3350. = (object) @Element
  3351. \*/
  3352. /*\
  3353. * Element.touchcancel
  3354. [ method ]
  3355. **
  3356. * Adds event handler for touchcancel for the element.
  3357. > Parameters
  3358. - handler (function) handler for the event
  3359. = (object) @Element
  3360. \*/
  3361. /*\
  3362. * Element.untouchcancel
  3363. [ method ]
  3364. **
  3365. * Removes event handler for touchcancel for the element.
  3366. > Parameters
  3367. - handler (function) #optional handler for the event
  3368. = (object) @Element
  3369. \*/
  3370. for (var i = events.length; i--;) {
  3371. (function (eventName) {
  3372. R[eventName] = elproto[eventName] = function (fn, scope) {
  3373. if (R.is(fn, "function")) {
  3374. this.events = this.events || [];
  3375. this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || g.doc, eventName, fn, scope || this)});
  3376. }
  3377. return this;
  3378. };
  3379. R["un" + eventName] = elproto["un" + eventName] = function (fn) {
  3380. var events = this.events || [],
  3381. l = events.length;
  3382. while (l--){
  3383. if (events[l].name == eventName && (R.is(fn, "undefined") || events[l].f == fn)) {
  3384. events[l].unbind();
  3385. events.splice(l, 1);
  3386. !events.length && delete this.events;
  3387. }
  3388. }
  3389. return this;
  3390. };
  3391. })(events[i]);
  3392. }
  3393. /*\
  3394. * Element.data
  3395. [ method ]
  3396. **
  3397. * Adds or retrieves given value asociated with given key.
  3398. **
  3399. * See also @Element.removeData
  3400. > Parameters
  3401. - key (string) key to store data
  3402. - value (any) #optional value to store
  3403. = (object) @Element
  3404. * or, if value is not specified:
  3405. = (any) value
  3406. * or, if key and value are not specified:
  3407. = (object) Key/value pairs for all the data associated with the element.
  3408. > Usage
  3409. | for (var i = 0, i < 5, i++) {
  3410. | paper.circle(10 + 15 * i, 10, 10)
  3411. | .attr({fill: "#000"})
  3412. | .data("i", i)
  3413. | .click(function () {
  3414. | alert(this.data("i"));
  3415. | });
  3416. | }
  3417. \*/
  3418. elproto.data = function (key, value) {
  3419. var data = eldata[this.id] = eldata[this.id] || {};
  3420. if (arguments.length == 0) {
  3421. return data;
  3422. }
  3423. if (arguments.length == 1) {
  3424. if (R.is(key, "object")) {
  3425. for (var i in key) if (key[has](i)) {
  3426. this.data(i, key[i]);
  3427. }
  3428. return this;
  3429. }
  3430. eve("raphael.data.get." + this.id, this, data[key], key);
  3431. return data[key];
  3432. }
  3433. data[key] = value;
  3434. eve("raphael.data.set." + this.id, this, value, key);
  3435. return this;
  3436. };
  3437. /*\
  3438. * Element.removeData
  3439. [ method ]
  3440. **
  3441. * Removes value associated with an element by given key.
  3442. * If key is not provided, removes all the data of the element.
  3443. > Parameters
  3444. - key (string) #optional key
  3445. = (object) @Element
  3446. \*/
  3447. elproto.removeData = function (key) {
  3448. if (key == null) {
  3449. eldata[this.id] = {};
  3450. } else {
  3451. eldata[this.id] && delete eldata[this.id][key];
  3452. }
  3453. return this;
  3454. };
  3455. /*\
  3456. * Element.getData
  3457. [ method ]
  3458. **
  3459. * Retrieves the element data
  3460. = (object) data
  3461. \*/
  3462. elproto.getData = function () {
  3463. return clone(eldata[this.id] || {});
  3464. };
  3465. /*\
  3466. * Element.hover
  3467. [ method ]
  3468. **
  3469. * Adds event handlers for hover for the element.
  3470. > Parameters
  3471. - f_in (function) handler for hover in
  3472. - f_out (function) handler for hover out
  3473. - icontext (object) #optional context for hover in handler
  3474. - ocontext (object) #optional context for hover out handler
  3475. = (object) @Element
  3476. \*/
  3477. elproto.hover = function (f_in, f_out, scope_in, scope_out) {
  3478. return this.mouseover(f_in, scope_in).mouseout(f_out, scope_out || scope_in);
  3479. };
  3480. /*\
  3481. * Element.unhover
  3482. [ method ]
  3483. **
  3484. * Removes event handlers for hover for the element.
  3485. > Parameters
  3486. - f_in (function) handler for hover in
  3487. - f_out (function) handler for hover out
  3488. = (object) @Element
  3489. \*/
  3490. elproto.unhover = function (f_in, f_out) {
  3491. return this.unmouseover(f_in).unmouseout(f_out);
  3492. };
  3493. var draggable = [];
  3494. /*\
  3495. * Element.drag
  3496. [ method ]
  3497. **
  3498. * Adds event handlers for drag of the element.
  3499. > Parameters
  3500. - onmove (function) handler for moving
  3501. - onstart (function) handler for drag start
  3502. - onend (function) handler for drag end
  3503. - mcontext (object) #optional context for moving handler
  3504. - scontext (object) #optional context for drag start handler
  3505. - econtext (object) #optional context for drag end handler
  3506. * Additionaly following `drag` events will be triggered: `drag.start.<id>` on start,
  3507. * `drag.end.<id>` on end and `drag.move.<id>` on every move. When element will be dragged over another element
  3508. * `drag.over.<id>` will be fired as well.
  3509. *
  3510. * Start event and start handler will be called in specified context or in context of the element with following parameters:
  3511. o x (number) x position of the mouse
  3512. o y (number) y position of the mouse
  3513. o event (object) DOM event object
  3514. * Move event and move handler will be called in specified context or in context of the element with following parameters:
  3515. o dx (number) shift by x from the start point
  3516. o dy (number) shift by y from the start point
  3517. o x (number) x position of the mouse
  3518. o y (number) y position of the mouse
  3519. o event (object) DOM event object
  3520. * End event and end handler will be called in specified context or in context of the element with following parameters:
  3521. o event (object) DOM event object
  3522. = (object) @Element
  3523. \*/
  3524. elproto.drag = function (onmove, onstart, onend, move_scope, start_scope, end_scope) {
  3525. function start(e) {
  3526. (e.originalEvent || e).preventDefault();
  3527. var x = e.clientX,
  3528. y = e.clientY,
  3529. scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  3530. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft;
  3531. this._drag.id = e.identifier;
  3532. if (supportsTouch && e.touches) {
  3533. var i = e.touches.length, touch;
  3534. while (i--) {
  3535. touch = e.touches[i];
  3536. this._drag.id = touch.identifier;
  3537. if (touch.identifier == this._drag.id) {
  3538. x = touch.clientX;
  3539. y = touch.clientY;
  3540. break;
  3541. }
  3542. }
  3543. }
  3544. this._drag.x = x + scrollX;
  3545. this._drag.y = y + scrollY;
  3546. !drag.length && R.mousemove(dragMove).mouseup(dragUp);
  3547. drag.push({el: this, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope});
  3548. onstart && eve.on("raphael.drag.start." + this.id, onstart);
  3549. onmove && eve.on("raphael.drag.move." + this.id, onmove);
  3550. onend && eve.on("raphael.drag.end." + this.id, onend);
  3551. eve("raphael.drag.start." + this.id, start_scope || move_scope || this, e.clientX + scrollX, e.clientY + scrollY, e);
  3552. }
  3553. this._drag = {};
  3554. draggable.push({el: this, start: start});
  3555. this.mousedown(start);
  3556. return this;
  3557. };
  3558. /*\
  3559. * Element.onDragOver
  3560. [ method ]
  3561. **
  3562. * Shortcut for assigning event handler for `drag.over.<id>` event, where id is id of the element (see @Element.id).
  3563. > Parameters
  3564. - f (function) handler for event, first argument would be the element you are dragging over
  3565. \*/
  3566. elproto.onDragOver = function (f) {
  3567. f ? eve.on("raphael.drag.over." + this.id, f) : eve.unbind("raphael.drag.over." + this.id);
  3568. };
  3569. /*\
  3570. * Element.undrag
  3571. [ method ]
  3572. **
  3573. * Removes all drag event handlers from given element.
  3574. \*/
  3575. elproto.undrag = function () {
  3576. var i = draggable.length;
  3577. while (i--) if (draggable[i].el == this) {
  3578. this.unmousedown(draggable[i].start);
  3579. draggable.splice(i, 1);
  3580. eve.unbind("raphael.drag.*." + this.id);
  3581. }
  3582. !draggable.length && R.unmousemove(dragMove).unmouseup(dragUp);
  3583. drag = [];
  3584. };
  3585. /*\
  3586. * Paper.circle
  3587. [ method ]
  3588. **
  3589. * Draws a circle.
  3590. **
  3591. > Parameters
  3592. **
  3593. - x (number) x coordinate of the centre
  3594. - y (number) y coordinate of the centre
  3595. - r (number) radius
  3596. = (object) Raphaël element object with type “circle”
  3597. **
  3598. > Usage
  3599. | var c = paper.circle(50, 50, 40);
  3600. \*/
  3601. paperproto.circle = function (x, y, r) {
  3602. var out = R._engine.circle(this, x || 0, y || 0, r || 0);
  3603. this.__set__ && this.__set__.push(out);
  3604. return out;
  3605. };
  3606. /*\
  3607. * Paper.rect
  3608. [ method ]
  3609. *
  3610. * Draws a rectangle.
  3611. **
  3612. > Parameters
  3613. **
  3614. - x (number) x coordinate of the top left corner
  3615. - y (number) y coordinate of the top left corner
  3616. - width (number) width
  3617. - height (number) height
  3618. - r (number) #optional radius for rounded corners, default is 0
  3619. = (object) Raphaël element object with type “rect”
  3620. **
  3621. > Usage
  3622. | // regular rectangle
  3623. | var c = paper.rect(10, 10, 50, 50);
  3624. | // rectangle with rounded corners
  3625. | var c = paper.rect(40, 40, 50, 50, 10);
  3626. \*/
  3627. paperproto.rect = function (x, y, w, h, r) {
  3628. var out = R._engine.rect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
  3629. this.__set__ && this.__set__.push(out);
  3630. return out;
  3631. };
  3632. /*\
  3633. * Paper.ellipse
  3634. [ method ]
  3635. **
  3636. * Draws an ellipse.
  3637. **
  3638. > Parameters
  3639. **
  3640. - x (number) x coordinate of the centre
  3641. - y (number) y coordinate of the centre
  3642. - rx (number) horizontal radius
  3643. - ry (number) vertical radius
  3644. = (object) Raphaël element object with type “ellipse”
  3645. **
  3646. > Usage
  3647. | var c = paper.ellipse(50, 50, 40, 20);
  3648. \*/
  3649. paperproto.ellipse = function (x, y, rx, ry) {
  3650. var out = R._engine.ellipse(this, x || 0, y || 0, rx || 0, ry || 0);
  3651. this.__set__ && this.__set__.push(out);
  3652. return out;
  3653. };
  3654. /*\
  3655. * Paper.path
  3656. [ method ]
  3657. **
  3658. * Creates a path element by given path data string.
  3659. > Parameters
  3660. - pathString (string) #optional path string in SVG format.
  3661. * Path string consists of one-letter commands, followed by comma seprarated arguments in numercal form. Example:
  3662. | "M10,20L30,40"
  3663. * Here we can see two commands: “M”, with arguments `(10, 20)` and “L” with arguments `(30, 40)`. Upper case letter mean command is absolute, lower case—relative.
  3664. *
  3665. # <p>Here is short list of commands available, for more details see <a href="http://www.w3.org/TR/SVG/paths.html#PathData" title="Details of a path's data attribute's format are described in the SVG specification.">SVG path string format</a>.</p>
  3666. # <table><thead><tr><th>Command</th><th>Name</th><th>Parameters</th></tr></thead><tbody>
  3667. # <tr><td>M</td><td>moveto</td><td>(x y)+</td></tr>
  3668. # <tr><td>Z</td><td>closepath</td><td>(none)</td></tr>
  3669. # <tr><td>L</td><td>lineto</td><td>(x y)+</td></tr>
  3670. # <tr><td>H</td><td>horizontal lineto</td><td>x+</td></tr>
  3671. # <tr><td>V</td><td>vertical lineto</td><td>y+</td></tr>
  3672. # <tr><td>C</td><td>curveto</td><td>(x1 y1 x2 y2 x y)+</td></tr>
  3673. # <tr><td>S</td><td>smooth curveto</td><td>(x2 y2 x y)+</td></tr>
  3674. # <tr><td>Q</td><td>quadratic Bézier curveto</td><td>(x1 y1 x y)+</td></tr>
  3675. # <tr><td>T</td><td>smooth quadratic Bézier curveto</td><td>(x y)+</td></tr>
  3676. # <tr><td>A</td><td>elliptical arc</td><td>(rx ry x-axis-rotation large-arc-flag sweep-flag x y)+</td></tr>
  3677. # <tr><td>R</td><td><a href="http://en.wikipedia.org/wiki/Catmull–Rom_spline#Catmull.E2.80.93Rom_spline">Catmull-Rom curveto</a>*</td><td>x1 y1 (x y)+</td></tr></tbody></table>
  3678. * * “Catmull-Rom curveto” is a not standard SVG command and added in 2.0 to make life easier.
  3679. * Note: there is a special case when path consist of just three commands: “M10,10R…z”. In this case path will smoothly connects to its beginning.
  3680. > Usage
  3681. | var c = paper.path("M10 10L90 90");
  3682. | // draw a diagonal line:
  3683. | // move to 10,10, line to 90,90
  3684. * For example of path strings, check out these icons: http://raphaeljs.com/icons/
  3685. \*/
  3686. paperproto.path = function (pathString) {
  3687. pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
  3688. var out = R._engine.path(R.format[apply](R, arguments), this);
  3689. this.__set__ && this.__set__.push(out);
  3690. return out;
  3691. };
  3692. /*\
  3693. * Paper.image
  3694. [ method ]
  3695. **
  3696. * Embeds an image into the surface.
  3697. **
  3698. > Parameters
  3699. **
  3700. - src (string) URI of the source image
  3701. - x (number) x coordinate position
  3702. - y (number) y coordinate position
  3703. - width (number) width of the image
  3704. - height (number) height of the image
  3705. = (object) Raphaël element object with type “image”
  3706. **
  3707. > Usage
  3708. | var c = paper.image("apple.png", 10, 10, 80, 80);
  3709. \*/
  3710. paperproto.image = function (src, x, y, w, h) {
  3711. var out = R._engine.image(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
  3712. this.__set__ && this.__set__.push(out);
  3713. return out;
  3714. };
  3715. /*\
  3716. * Paper.text
  3717. [ method ]
  3718. **
  3719. * Draws a text string. If you need line breaks, put “\n” in the string.
  3720. **
  3721. > Parameters
  3722. **
  3723. - x (number) x coordinate position
  3724. - y (number) y coordinate position
  3725. - text (string) The text string to draw
  3726. = (object) Raphaël element object with type “text”
  3727. **
  3728. > Usage
  3729. | var t = paper.text(50, 50, "Raphaël\nkicks\nbutt!");
  3730. \*/
  3731. paperproto.text = function (x, y, text) {
  3732. var out = R._engine.text(this, x || 0, y || 0, Str(text));
  3733. this.__set__ && this.__set__.push(out);
  3734. return out;
  3735. };
  3736. /*\
  3737. * Paper.set
  3738. [ method ]
  3739. **
  3740. * Creates array-like object to keep and operate several elements at once.
  3741. * Warning: it doesn’t create any elements for itself in the page, it just groups existing elements.
  3742. * Sets act as pseudo elements — all methods available to an element can be used on a set.
  3743. = (object) array-like object that represents set of elements
  3744. **
  3745. > Usage
  3746. | var st = paper.set();
  3747. | st.push(
  3748. | paper.circle(10, 10, 5),
  3749. | paper.circle(30, 10, 5)
  3750. | );
  3751. | st.attr({fill: "red"}); // changes the fill of both circles
  3752. \*/
  3753. paperproto.set = function (itemsArray) {
  3754. !R.is(itemsArray, "array") && (itemsArray = Array.prototype.splice.call(arguments, 0, arguments.length));
  3755. var out = new Set(itemsArray);
  3756. this.__set__ && this.__set__.push(out);
  3757. out["paper"] = this;
  3758. out["type"] = "set";
  3759. return out;
  3760. };
  3761. /*\
  3762. * Paper.setStart
  3763. [ method ]
  3764. **
  3765. * Creates @Paper.set. All elements that will be created after calling this method and before calling
  3766. * @Paper.setFinish will be added to the set.
  3767. **
  3768. > Usage
  3769. | paper.setStart();
  3770. | paper.circle(10, 10, 5),
  3771. | paper.circle(30, 10, 5)
  3772. | var st = paper.setFinish();
  3773. | st.attr({fill: "red"}); // changes the fill of both circles
  3774. \*/
  3775. paperproto.setStart = function (set) {
  3776. this.__set__ = set || this.set();
  3777. };
  3778. /*\
  3779. * Paper.setFinish
  3780. [ method ]
  3781. **
  3782. * See @Paper.setStart. This method finishes catching and returns resulting set.
  3783. **
  3784. = (object) set
  3785. \*/
  3786. paperproto.setFinish = function (set) {
  3787. var out = this.__set__;
  3788. delete this.__set__;
  3789. return out;
  3790. };
  3791. /*\
  3792. * Paper.setSize
  3793. [ method ]
  3794. **
  3795. * If you need to change dimensions of the canvas call this method
  3796. **
  3797. > Parameters
  3798. **
  3799. - width (number) new width of the canvas
  3800. - height (number) new height of the canvas
  3801. \*/
  3802. paperproto.setSize = function (width, height) {
  3803. return R._engine.setSize.call(this, width, height);
  3804. };
  3805. /*\
  3806. * Paper.setViewBox
  3807. [ method ]
  3808. **
  3809. * Sets the view box of the paper. Practically it gives you ability to zoom and pan whole paper surface by
  3810. * specifying new boundaries.
  3811. **
  3812. > Parameters
  3813. **
  3814. - x (number) new x position, default is `0`
  3815. - y (number) new y position, default is `0`
  3816. - w (number) new width of the canvas
  3817. - h (number) new height of the canvas
  3818. - fit (boolean) `true` if you want graphics to fit into new boundary box
  3819. \*/
  3820. paperproto.setViewBox = function (x, y, w, h, fit) {
  3821. return R._engine.setViewBox.call(this, x, y, w, h, fit);
  3822. };
  3823. /*\
  3824. * Paper.top
  3825. [ property ]
  3826. **
  3827. * Points to the topmost element on the paper
  3828. \*/
  3829. /*\
  3830. * Paper.bottom
  3831. [ property ]
  3832. **
  3833. * Points to the bottom element on the paper
  3834. \*/
  3835. paperproto.top = paperproto.bottom = null;
  3836. /*\
  3837. * Paper.raphael
  3838. [ property ]
  3839. **
  3840. * Points to the @Raphael object/function
  3841. \*/
  3842. paperproto.raphael = R;
  3843. var getOffset = function (elem) {
  3844. var box = elem.getBoundingClientRect(),
  3845. doc = elem.ownerDocument,
  3846. body = doc.body,
  3847. docElem = doc.documentElement,
  3848. clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
  3849. top = box.top + (g.win.pageYOffset || docElem.scrollTop || body.scrollTop ) - clientTop,
  3850. left = box.left + (g.win.pageXOffset || docElem.scrollLeft || body.scrollLeft) - clientLeft;
  3851. return {
  3852. y: top,
  3853. x: left
  3854. };
  3855. };
  3856. /*\
  3857. * Paper.getElementByPoint
  3858. [ method ]
  3859. **
  3860. * Returns you topmost element under given point.
  3861. **
  3862. = (object) Raphaël element object
  3863. > Parameters
  3864. **
  3865. - x (number) x coordinate from the top left corner of the window
  3866. - y (number) y coordinate from the top left corner of the window
  3867. > Usage
  3868. | paper.getElementByPoint(mouseX, mouseY).attr({stroke: "#f00"});
  3869. \*/
  3870. paperproto.getElementByPoint = function (x, y) {
  3871. var paper = this,
  3872. svg = paper.canvas,
  3873. target = g.doc.elementFromPoint(x, y);
  3874. if (g.win.opera && target.tagName == "svg") {
  3875. var so = getOffset(svg),
  3876. sr = svg.createSVGRect();
  3877. sr.x = x - so.x;
  3878. sr.y = y - so.y;
  3879. sr.width = sr.height = 1;
  3880. var hits = svg.getIntersectionList(sr, null);
  3881. if (hits.length) {
  3882. target = hits[hits.length - 1];
  3883. }
  3884. }
  3885. if (!target) {
  3886. return null;
  3887. }
  3888. while (target.parentNode && target != svg.parentNode && !target.raphael) {
  3889. target = target.parentNode;
  3890. }
  3891. target == paper.canvas.parentNode && (target = svg);
  3892. target = target && target.raphael ? paper.getById(target.raphaelid) : null;
  3893. return target;
  3894. };
  3895. /*\
  3896. * Paper.getElementsByBBox
  3897. [ method ]
  3898. **
  3899. * Returns set of elements that have an intersecting bounding box
  3900. **
  3901. > Parameters
  3902. **
  3903. - bbox (object) bbox to check with
  3904. = (object) @Set
  3905. \*/
  3906. paperproto.getElementsByBBox = function (bbox) {
  3907. var set = this.set();
  3908. this.forEach(function (el) {
  3909. if (R.isBBoxIntersect(el.getBBox(), bbox)) {
  3910. set.push(el);
  3911. }
  3912. });
  3913. return set;
  3914. };
  3915. /*\
  3916. * Paper.getById
  3917. [ method ]
  3918. **
  3919. * Returns you element by its internal ID.
  3920. **
  3921. > Parameters
  3922. **
  3923. - id (number) id
  3924. = (object) Raphaël element object
  3925. \*/
  3926. paperproto.getById = function (id) {
  3927. var bot = this.bottom;
  3928. while (bot) {
  3929. if (bot.id == id) {
  3930. return bot;
  3931. }
  3932. bot = bot.next;
  3933. }
  3934. return null;
  3935. };
  3936. /*\
  3937. * Paper.forEach
  3938. [ method ]
  3939. **
  3940. * Executes given function for each element on the paper
  3941. *
  3942. * If callback function returns `false` it will stop loop running.
  3943. **
  3944. > Parameters
  3945. **
  3946. - callback (function) function to run
  3947. - thisArg (object) context object for the callback
  3948. = (object) Paper object
  3949. > Usage
  3950. | paper.forEach(function (el) {
  3951. | el.attr({ stroke: "blue" });
  3952. | });
  3953. \*/
  3954. paperproto.forEach = function (callback, thisArg) {
  3955. var bot = this.bottom;
  3956. while (bot) {
  3957. if (callback.call(thisArg, bot) === false) {
  3958. return this;
  3959. }
  3960. bot = bot.next;
  3961. }
  3962. return this;
  3963. };
  3964. /*\
  3965. * Paper.getElementsByPoint
  3966. [ method ]
  3967. **
  3968. * Returns set of elements that have common point inside
  3969. **
  3970. > Parameters
  3971. **
  3972. - x (number) x coordinate of the point
  3973. - y (number) y coordinate of the point
  3974. = (object) @Set
  3975. \*/
  3976. paperproto.getElementsByPoint = function (x, y) {
  3977. var set = this.set();
  3978. this.forEach(function (el) {
  3979. if (el.isPointInside(x, y)) {
  3980. set.push(el);
  3981. }
  3982. });
  3983. return set;
  3984. };
  3985. function x_y() {
  3986. return this.x + S + this.y;
  3987. }
  3988. function x_y_w_h() {
  3989. return this.x + S + this.y + S + this.width + " \xd7 " + this.height;
  3990. }
  3991. /*\
  3992. * Element.isPointInside
  3993. [ method ]
  3994. **
  3995. * Determine if given point is inside this element’s shape
  3996. **
  3997. > Parameters
  3998. **
  3999. - x (number) x coordinate of the point
  4000. - y (number) y coordinate of the point
  4001. = (boolean) `true` if point inside the shape
  4002. \*/
  4003. elproto.isPointInside = function (x, y) {
  4004. var rp = this.realPath = getPath[this.type](this);
  4005. if (this.attr('transform') && this.attr('transform').length) {
  4006. rp = R.transformPath(rp, this.attr('transform'));
  4007. }
  4008. return R.isPointInsidePath(rp, x, y);
  4009. };
  4010. /*\
  4011. * Element.getBBox
  4012. [ method ]
  4013. **
  4014. * Return bounding box for a given element
  4015. **
  4016. > Parameters
  4017. **
  4018. - isWithoutTransform (boolean) flag, `true` if you want to have bounding box before transformations. Default is `false`.
  4019. = (object) Bounding box object:
  4020. o {
  4021. o x: (number) top left corner x
  4022. o y: (number) top left corner y
  4023. o x2: (number) bottom right corner x
  4024. o y2: (number) bottom right corner y
  4025. o width: (number) width
  4026. o height: (number) height
  4027. o }
  4028. \*/
  4029. elproto.getBBox = function (isWithoutTransform) {
  4030. if (this.removed) {
  4031. return {};
  4032. }
  4033. var _ = this._;
  4034. if (isWithoutTransform) {
  4035. if (_.dirty || !_.bboxwt) {
  4036. this.realPath = getPath[this.type](this);
  4037. _.bboxwt = pathDimensions(this.realPath);
  4038. _.bboxwt.toString = x_y_w_h;
  4039. _.dirty = 0;
  4040. }
  4041. return _.bboxwt;
  4042. }
  4043. if (_.dirty || _.dirtyT || !_.bbox) {
  4044. if (_.dirty || !this.realPath) {
  4045. _.bboxwt = 0;
  4046. this.realPath = getPath[this.type](this);
  4047. }
  4048. _.bbox = pathDimensions(mapPath(this.realPath, this.matrix));
  4049. _.bbox.toString = x_y_w_h;
  4050. _.dirty = _.dirtyT = 0;
  4051. }
  4052. return _.bbox;
  4053. };
  4054. /*\
  4055. * Element.clone
  4056. [ method ]
  4057. **
  4058. = (object) clone of a given element
  4059. **
  4060. \*/
  4061. elproto.clone = function () {
  4062. if (this.removed) {
  4063. return null;
  4064. }
  4065. var out = this.paper[this.type]().attr(this.attr());
  4066. this.__set__ && this.__set__.push(out);
  4067. return out;
  4068. };
  4069. /*\
  4070. * Element.glow
  4071. [ method ]
  4072. **
  4073. * Return set of elements that create glow-like effect around given element. See @Paper.set.
  4074. *
  4075. * Note: Glow is not connected to the element. If you change element attributes it won’t adjust itself.
  4076. **
  4077. > Parameters
  4078. **
  4079. - glow (object) #optional parameters object with all properties optional:
  4080. o {
  4081. o width (number) size of the glow, default is `10`
  4082. o fill (boolean) will it be filled, default is `false`
  4083. o opacity (number) opacity, default is `0.5`
  4084. o offsetx (number) horizontal offset, default is `0`
  4085. o offsety (number) vertical offset, default is `0`
  4086. o color (string) glow colour, default is `black`
  4087. o }
  4088. = (object) @Paper.set of elements that represents glow
  4089. \*/
  4090. elproto.glow = function (glow) {
  4091. if (this.type == "text") {
  4092. return null;
  4093. }
  4094. glow = glow || {};
  4095. var s = {
  4096. width: (glow.width || 10) + (+this.attr("stroke-width") || 1),
  4097. fill: glow.fill || false,
  4098. opacity: glow.opacity || .5,
  4099. offsetx: glow.offsetx || 0,
  4100. offsety: glow.offsety || 0,
  4101. color: glow.color || "#000"
  4102. },
  4103. c = s.width / 2,
  4104. r = this.paper,
  4105. out = r.set(),
  4106. path = this.realPath || getPath[this.type](this);
  4107. path = this.matrix ? mapPath(path, this.matrix) : path;
  4108. for (var i = 1; i < c + 1; i++) {
  4109. out.push(r.path(path).attr({
  4110. stroke: s.color,
  4111. fill: s.fill ? s.color : "none",
  4112. "stroke-linejoin": "round",
  4113. "stroke-linecap": "round",
  4114. "stroke-width": +(s.width / c * i).toFixed(3),
  4115. opacity: +(s.opacity / c).toFixed(3)
  4116. }));
  4117. }
  4118. return out.insertBefore(this).translate(s.offsetx, s.offsety);
  4119. };
  4120. var curveslengths = {},
  4121. getPointAtSegmentLength = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
  4122. if (length == null) {
  4123. return bezlen(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
  4124. } else {
  4125. return R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, getTatLen(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length));
  4126. }
  4127. },
  4128. getLengthFactory = function (istotal, subpath) {
  4129. return function (path, length, onlystart) {
  4130. path = path2curve(path);
  4131. var x, y, p, l, sp = "", subpaths = {}, point,
  4132. len = 0;
  4133. for (var i = 0, ii = path.length; i < ii; i++) {
  4134. p = path[i];
  4135. if (p[0] == "M") {
  4136. x = +p[1];
  4137. y = +p[2];
  4138. } else {
  4139. l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
  4140. if (len + l > length) {
  4141. if (subpath && !subpaths.start) {
  4142. point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
  4143. sp += ["C" + point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
  4144. if (onlystart) {return sp;}
  4145. subpaths.start = sp;
  4146. sp = ["M" + point.x, point.y + "C" + point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]].join();
  4147. len += l;
  4148. x = +p[5];
  4149. y = +p[6];
  4150. continue;
  4151. }
  4152. if (!istotal && !subpath) {
  4153. point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
  4154. return {x: point.x, y: point.y, alpha: point.alpha};
  4155. }
  4156. }
  4157. len += l;
  4158. x = +p[5];
  4159. y = +p[6];
  4160. }
  4161. sp += p.shift() + p;
  4162. }
  4163. subpaths.end = sp;
  4164. point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[0], p[1], p[2], p[3], p[4], p[5], 1);
  4165. point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
  4166. return point;
  4167. };
  4168. };
  4169. var getTotalLength = getLengthFactory(1),
  4170. getPointAtLength = getLengthFactory(),
  4171. getSubpathsAtLength = getLengthFactory(0, 1);
  4172. /*\
  4173. * Raphael.getTotalLength
  4174. [ method ]
  4175. **
  4176. * Returns length of the given path in pixels.
  4177. **
  4178. > Parameters
  4179. **
  4180. - path (string) SVG path string.
  4181. **
  4182. = (number) length.
  4183. \*/
  4184. R.getTotalLength = getTotalLength;
  4185. /*\
  4186. * Raphael.getPointAtLength
  4187. [ method ]
  4188. **
  4189. * Return coordinates of the point located at the given length on the given path.
  4190. **
  4191. > Parameters
  4192. **
  4193. - path (string) SVG path string
  4194. - length (number)
  4195. **
  4196. = (object) representation of the point:
  4197. o {
  4198. o x: (number) x coordinate
  4199. o y: (number) y coordinate
  4200. o alpha: (number) angle of derivative
  4201. o }
  4202. \*/
  4203. R.getPointAtLength = getPointAtLength;
  4204. /*\
  4205. * Raphael.getSubpath
  4206. [ method ]
  4207. **
  4208. * Return subpath of a given path from given length to given length.
  4209. **
  4210. > Parameters
  4211. **
  4212. - path (string) SVG path string
  4213. - from (number) position of the start of the segment
  4214. - to (number) position of the end of the segment
  4215. **
  4216. = (string) pathstring for the segment
  4217. \*/
  4218. R.getSubpath = function (path, from, to) {
  4219. if (this.getTotalLength(path) - to < 1e-6) {
  4220. return getSubpathsAtLength(path, from).end;
  4221. }
  4222. var a = getSubpathsAtLength(path, to, 1);
  4223. return from ? getSubpathsAtLength(a, from).end : a;
  4224. };
  4225. /*\
  4226. * Element.getTotalLength
  4227. [ method ]
  4228. **
  4229. * Returns length of the path in pixels. Only works for element of “path” type.
  4230. = (number) length.
  4231. \*/
  4232. elproto.getTotalLength = function () {
  4233. var path = this.getPath();
  4234. if (!path) {
  4235. return;
  4236. }
  4237. if (this.node.getTotalLength) {
  4238. return this.node.getTotalLength();
  4239. }
  4240. return getTotalLength(path);
  4241. };
  4242. /*\
  4243. * Element.getPointAtLength
  4244. [ method ]
  4245. **
  4246. * Return coordinates of the point located at the given length on the given path. Only works for element of “path” type.
  4247. **
  4248. > Parameters
  4249. **
  4250. - length (number)
  4251. **
  4252. = (object) representation of the point:
  4253. o {
  4254. o x: (number) x coordinate
  4255. o y: (number) y coordinate
  4256. o alpha: (number) angle of derivative
  4257. o }
  4258. \*/
  4259. elproto.getPointAtLength = function (length) {
  4260. var path = this.getPath();
  4261. if (!path) {
  4262. return;
  4263. }
  4264. return getPointAtLength(path, length);
  4265. };
  4266. /*\
  4267. * Element.getPath
  4268. [ method ]
  4269. **
  4270. * Returns path of the element. Only works for elements of “path” type and simple elements like circle.
  4271. = (object) path
  4272. **
  4273. \*/
  4274. elproto.getPath = function () {
  4275. var path,
  4276. getPath = R._getPath[this.type];
  4277. if (this.type == "text" || this.type == "set") {
  4278. return;
  4279. }
  4280. if (getPath) {
  4281. path = getPath(this);
  4282. }
  4283. return path;
  4284. };
  4285. /*\
  4286. * Element.getSubpath
  4287. [ method ]
  4288. **
  4289. * Return subpath of a given element from given length to given length. Only works for element of “path” type.
  4290. **
  4291. > Parameters
  4292. **
  4293. - from (number) position of the start of the segment
  4294. - to (number) position of the end of the segment
  4295. **
  4296. = (string) pathstring for the segment
  4297. \*/
  4298. elproto.getSubpath = function (from, to) {
  4299. var path = this.getPath();
  4300. if (!path) {
  4301. return;
  4302. }
  4303. return R.getSubpath(path, from, to);
  4304. };
  4305. /*\
  4306. * Raphael.easing_formulas
  4307. [ property ]
  4308. **
  4309. * Object that contains easing formulas for animation. You could extend it with your own. By default it has following list of easing:
  4310. # <ul>
  4311. # <li>“linear”</li>
  4312. # <li>“&lt;” or “easeIn” or “ease-in”</li>
  4313. # <li>“>” or “easeOut” or “ease-out”</li>
  4314. # <li>“&lt;>” or “easeInOut” or “ease-in-out”</li>
  4315. # <li>“backIn” or “back-in”</li>
  4316. # <li>“backOut” or “back-out”</li>
  4317. # <li>“elastic”</li>
  4318. # <li>“bounce”</li>
  4319. # </ul>
  4320. # <p>See also <a href="http://raphaeljs.com/easing.html">Easing demo</a>.</p>
  4321. \*/
  4322. var ef = R.easing_formulas = {
  4323. linear: function (n) {
  4324. return n;
  4325. },
  4326. "<": function (n) {
  4327. return pow(n, 1.7);
  4328. },
  4329. ">": function (n) {
  4330. return pow(n, .48);
  4331. },
  4332. "<>": function (n) {
  4333. var q = .48 - n / 1.04,
  4334. Q = math.sqrt(.1734 + q * q),
  4335. x = Q - q,
  4336. X = pow(abs(x), 1 / 3) * (x < 0 ? -1 : 1),
  4337. y = -Q - q,
  4338. Y = pow(abs(y), 1 / 3) * (y < 0 ? -1 : 1),
  4339. t = X + Y + .5;
  4340. return (1 - t) * 3 * t * t + t * t * t;
  4341. },
  4342. backIn: function (n) {
  4343. var s = 1.70158;
  4344. return n * n * ((s + 1) * n - s);
  4345. },
  4346. backOut: function (n) {
  4347. n = n - 1;
  4348. var s = 1.70158;
  4349. return n * n * ((s + 1) * n + s) + 1;
  4350. },
  4351. elastic: function (n) {
  4352. if (n == !!n) {
  4353. return n;
  4354. }
  4355. return pow(2, -10 * n) * math.sin((n - .075) * (2 * PI) / .3) + 1;
  4356. },
  4357. bounce: function (n) {
  4358. var s = 7.5625,
  4359. p = 2.75,
  4360. l;
  4361. if (n < (1 / p)) {
  4362. l = s * n * n;
  4363. } else {
  4364. if (n < (2 / p)) {
  4365. n -= (1.5 / p);
  4366. l = s * n * n + .75;
  4367. } else {
  4368. if (n < (2.5 / p)) {
  4369. n -= (2.25 / p);
  4370. l = s * n * n + .9375;
  4371. } else {
  4372. n -= (2.625 / p);
  4373. l = s * n * n + .984375;
  4374. }
  4375. }
  4376. }
  4377. return l;
  4378. }
  4379. };
  4380. ef.easeIn = ef["ease-in"] = ef["<"];
  4381. ef.easeOut = ef["ease-out"] = ef[">"];
  4382. ef.easeInOut = ef["ease-in-out"] = ef["<>"];
  4383. ef["back-in"] = ef.backIn;
  4384. ef["back-out"] = ef.backOut;
  4385. var animationElements = [],
  4386. requestAnimFrame = window.requestAnimationFrame ||
  4387. window.webkitRequestAnimationFrame ||
  4388. window.mozRequestAnimationFrame ||
  4389. window.oRequestAnimationFrame ||
  4390. window.msRequestAnimationFrame ||
  4391. function (callback) {
  4392. setTimeout(callback, 16);
  4393. },
  4394. animation = function () {
  4395. var Now = +new Date,
  4396. l = 0;
  4397. for (; l < animationElements.length; l++) {
  4398. var e = animationElements[l];
  4399. if (e.el.removed || e.paused) {
  4400. continue;
  4401. }
  4402. var time = Now - e.start,
  4403. ms = e.ms,
  4404. easing = e.easing,
  4405. from = e.from,
  4406. diff = e.diff,
  4407. to = e.to,
  4408. t = e.t,
  4409. that = e.el,
  4410. set = {},
  4411. now,
  4412. init = {},
  4413. key;
  4414. if (e.initstatus) {
  4415. time = (e.initstatus * e.anim.top - e.prev) / (e.percent - e.prev) * ms;
  4416. e.status = e.initstatus;
  4417. delete e.initstatus;
  4418. e.stop && animationElements.splice(l--, 1);
  4419. } else {
  4420. e.status = (e.prev + (e.percent - e.prev) * (time / ms)) / e.anim.top;
  4421. }
  4422. if (time < 0) {
  4423. continue;
  4424. }
  4425. if (time < ms) {
  4426. var pos = easing(time / ms);
  4427. for (var attr in from) if (from[has](attr)) {
  4428. switch (availableAnimAttrs[attr]) {
  4429. case nu:
  4430. now = +from[attr] + pos * ms * diff[attr];
  4431. break;
  4432. case "colour":
  4433. now = "rgb(" + [
  4434. upto255(round(from[attr].r + pos * ms * diff[attr].r)),
  4435. upto255(round(from[attr].g + pos * ms * diff[attr].g)),
  4436. upto255(round(from[attr].b + pos * ms * diff[attr].b))
  4437. ].join(",") + ")";
  4438. break;
  4439. case "path":
  4440. now = [];
  4441. for (var i = 0, ii = from[attr].length; i < ii; i++) {
  4442. now[i] = [from[attr][i][0]];
  4443. for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
  4444. now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
  4445. }
  4446. now[i] = now[i].join(S);
  4447. }
  4448. now = now.join(S);
  4449. break;
  4450. case "transform":
  4451. if (diff[attr].real) {
  4452. now = [];
  4453. for (i = 0, ii = from[attr].length; i < ii; i++) {
  4454. now[i] = [from[attr][i][0]];
  4455. for (j = 1, jj = from[attr][i].length; j < jj; j++) {
  4456. now[i][j] = from[attr][i][j] + pos * ms * diff[attr][i][j];
  4457. }
  4458. }
  4459. } else {
  4460. var get = function (i) {
  4461. return +from[attr][i] + pos * ms * diff[attr][i];
  4462. };
  4463. // now = [["r", get(2), 0, 0], ["t", get(3), get(4)], ["s", get(0), get(1), 0, 0]];
  4464. now = [["m", get(0), get(1), get(2), get(3), get(4), get(5)]];
  4465. }
  4466. break;
  4467. case "csv":
  4468. if (attr == "clip-rect") {
  4469. now = [];
  4470. i = 4;
  4471. while (i--) {
  4472. now[i] = +from[attr][i] + pos * ms * diff[attr][i];
  4473. }
  4474. }
  4475. break;
  4476. default:
  4477. var from2 = [][concat](from[attr]);
  4478. now = [];
  4479. i = that.paper.customAttributes[attr].length;
  4480. while (i--) {
  4481. now[i] = +from2[i] + pos * ms * diff[attr][i];
  4482. }
  4483. break;
  4484. }
  4485. set[attr] = now;
  4486. }
  4487. that.attr(set);
  4488. (function (id, that, anim) {
  4489. setTimeout(function () {
  4490. eve("raphael.anim.frame." + id, that, anim);
  4491. });
  4492. })(that.id, that, e.anim);
  4493. } else {
  4494. (function(f, el, a) {
  4495. setTimeout(function() {
  4496. eve("raphael.anim.frame." + el.id, el, a);
  4497. eve("raphael.anim.finish." + el.id, el, a);
  4498. R.is(f, "function") && f.call(el);
  4499. });
  4500. })(e.callback, that, e.anim);
  4501. that.attr(to);
  4502. animationElements.splice(l--, 1);
  4503. if (e.repeat > 1 && !e.next) {
  4504. for (key in to) if (to[has](key)) {
  4505. init[key] = e.totalOrigin[key];
  4506. }
  4507. e.el.attr(init);
  4508. runAnimation(e.anim, e.el, e.anim.percents[0], null, e.totalOrigin, e.repeat - 1);
  4509. }
  4510. if (e.next && !e.stop) {
  4511. runAnimation(e.anim, e.el, e.next, null, e.totalOrigin, e.repeat);
  4512. }
  4513. }
  4514. }
  4515. R.svg && that && that.paper && that.paper.safari();
  4516. animationElements.length && requestAnimFrame(animation);
  4517. },
  4518. upto255 = function (color) {
  4519. return color > 255 ? 255 : color < 0 ? 0 : color;
  4520. };
  4521. /*\
  4522. * Element.animateWith
  4523. [ method ]
  4524. **
  4525. * Acts similar to @Element.animate, but ensure that given animation runs in sync with another given element.
  4526. **
  4527. > Parameters
  4528. **
  4529. - el (object) element to sync with
  4530. - anim (object) animation to sync with
  4531. - params (object) #optional final attributes for the element, see also @Element.attr
  4532. - ms (number) #optional number of milliseconds for animation to run
  4533. - easing (string) #optional easing type. Accept on of @Raphael.easing_formulas or CSS format: `cubic&#x2010;bezier(XX,&#160;XX,&#160;XX,&#160;XX)`
  4534. - callback (function) #optional callback function. Will be called at the end of animation.
  4535. * or
  4536. - element (object) element to sync with
  4537. - anim (object) animation to sync with
  4538. - animation (object) #optional animation object, see @Raphael.animation
  4539. **
  4540. = (object) original element
  4541. \*/
  4542. elproto.animateWith = function (el, anim, params, ms, easing, callback) {
  4543. var element = this;
  4544. if (element.removed) {
  4545. callback && callback.call(element);
  4546. return element;
  4547. }
  4548. var a = params instanceof Animation ? params : R.animation(params, ms, easing, callback),
  4549. x, y;
  4550. runAnimation(a, element, a.percents[0], null, element.attr());
  4551. for (var i = 0, ii = animationElements.length; i < ii; i++) {
  4552. if (animationElements[i].anim == anim && animationElements[i].el == el) {
  4553. animationElements[ii - 1].start = animationElements[i].start;
  4554. break;
  4555. }
  4556. }
  4557. return element;
  4558. //
  4559. //
  4560. // var a = params ? R.animation(params, ms, easing, callback) : anim,
  4561. // status = element.status(anim);
  4562. // return this.animate(a).status(a, status * anim.ms / a.ms);
  4563. };
  4564. function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
  4565. var cx = 3 * p1x,
  4566. bx = 3 * (p2x - p1x) - cx,
  4567. ax = 1 - cx - bx,
  4568. cy = 3 * p1y,
  4569. by = 3 * (p2y - p1y) - cy,
  4570. ay = 1 - cy - by;
  4571. function sampleCurveX(t) {
  4572. return ((ax * t + bx) * t + cx) * t;
  4573. }
  4574. function solve(x, epsilon) {
  4575. var t = solveCurveX(x, epsilon);
  4576. return ((ay * t + by) * t + cy) * t;
  4577. }
  4578. function solveCurveX(x, epsilon) {
  4579. var t0, t1, t2, x2, d2, i;
  4580. for(t2 = x, i = 0; i < 8; i++) {
  4581. x2 = sampleCurveX(t2) - x;
  4582. if (abs(x2) < epsilon) {
  4583. return t2;
  4584. }
  4585. d2 = (3 * ax * t2 + 2 * bx) * t2 + cx;
  4586. if (abs(d2) < 1e-6) {
  4587. break;
  4588. }
  4589. t2 = t2 - x2 / d2;
  4590. }
  4591. t0 = 0;
  4592. t1 = 1;
  4593. t2 = x;
  4594. if (t2 < t0) {
  4595. return t0;
  4596. }
  4597. if (t2 > t1) {
  4598. return t1;
  4599. }
  4600. while (t0 < t1) {
  4601. x2 = sampleCurveX(t2);
  4602. if (abs(x2 - x) < epsilon) {
  4603. return t2;
  4604. }
  4605. if (x > x2) {
  4606. t0 = t2;
  4607. } else {
  4608. t1 = t2;
  4609. }
  4610. t2 = (t1 - t0) / 2 + t0;
  4611. }
  4612. return t2;
  4613. }
  4614. return solve(t, 1 / (200 * duration));
  4615. }
  4616. elproto.onAnimation = function (f) {
  4617. f ? eve.on("raphael.anim.frame." + this.id, f) : eve.unbind("raphael.anim.frame." + this.id);
  4618. return this;
  4619. };
  4620. function Animation(anim, ms) {
  4621. var percents = [],
  4622. newAnim = {};
  4623. this.ms = ms;
  4624. this.times = 1;
  4625. if (anim) {
  4626. for (var attr in anim) if (anim[has](attr)) {
  4627. newAnim[toFloat(attr)] = anim[attr];
  4628. percents.push(toFloat(attr));
  4629. }
  4630. percents.sort(sortByNumber);
  4631. }
  4632. this.anim = newAnim;
  4633. this.top = percents[percents.length - 1];
  4634. this.percents = percents;
  4635. }
  4636. /*\
  4637. * Animation.delay
  4638. [ method ]
  4639. **
  4640. * Creates a copy of existing animation object with given delay.
  4641. **
  4642. > Parameters
  4643. **
  4644. - delay (number) number of ms to pass between animation start and actual animation
  4645. **
  4646. = (object) new altered Animation object
  4647. | var anim = Raphael.animation({cx: 10, cy: 20}, 2e3);
  4648. | circle1.animate(anim); // run the given animation immediately
  4649. | circle2.animate(anim.delay(500)); // run the given animation after 500 ms
  4650. \*/
  4651. Animation.prototype.delay = function (delay) {
  4652. var a = new Animation(this.anim, this.ms);
  4653. a.times = this.times;
  4654. a.del = +delay || 0;
  4655. return a;
  4656. };
  4657. /*\
  4658. * Animation.repeat
  4659. [ method ]
  4660. **
  4661. * Creates a copy of existing animation object with given repetition.
  4662. **
  4663. > Parameters
  4664. **
  4665. - repeat (number) number iterations of animation. For infinite animation pass `Infinity`
  4666. **
  4667. = (object) new altered Animation object
  4668. \*/
  4669. Animation.prototype.repeat = function (times) {
  4670. var a = new Animation(this.anim, this.ms);
  4671. a.del = this.del;
  4672. a.times = math.floor(mmax(times, 0)) || 1;
  4673. return a;
  4674. };
  4675. function runAnimation(anim, element, percent, status, totalOrigin, times) {
  4676. percent = toFloat(percent);
  4677. var params,
  4678. isInAnim,
  4679. isInAnimSet,
  4680. percents = [],
  4681. next,
  4682. prev,
  4683. timestamp,
  4684. ms = anim.ms,
  4685. from = {},
  4686. to = {},
  4687. diff = {};
  4688. if (status) {
  4689. for (i = 0, ii = animationElements.length; i < ii; i++) {
  4690. var e = animationElements[i];
  4691. if (e.el.id == element.id && e.anim == anim) {
  4692. if (e.percent != percent) {
  4693. animationElements.splice(i, 1);
  4694. isInAnimSet = 1;
  4695. } else {
  4696. isInAnim = e;
  4697. }
  4698. element.attr(e.totalOrigin);
  4699. break;
  4700. }
  4701. }
  4702. } else {
  4703. status = +to; // NaN
  4704. }
  4705. for (var i = 0, ii = anim.percents.length; i < ii; i++) {
  4706. if (anim.percents[i] == percent || anim.percents[i] > status * anim.top) {
  4707. percent = anim.percents[i];
  4708. prev = anim.percents[i - 1] || 0;
  4709. ms = ms / anim.top * (percent - prev);
  4710. next = anim.percents[i + 1];
  4711. params = anim.anim[percent];
  4712. break;
  4713. } else if (status) {
  4714. element.attr(anim.anim[anim.percents[i]]);
  4715. }
  4716. }
  4717. if (!params) {
  4718. return;
  4719. }
  4720. if (!isInAnim) {
  4721. for (var attr in params) if (params[has](attr)) {
  4722. if (availableAnimAttrs[has](attr) || element.paper.customAttributes[has](attr)) {
  4723. from[attr] = element.attr(attr);
  4724. (from[attr] == null) && (from[attr] = availableAttrs[attr]);
  4725. to[attr] = params[attr];
  4726. switch (availableAnimAttrs[attr]) {
  4727. case nu:
  4728. diff[attr] = (to[attr] - from[attr]) / ms;
  4729. break;
  4730. case "colour":
  4731. from[attr] = R.getRGB(from[attr]);
  4732. var toColour = R.getRGB(to[attr]);
  4733. diff[attr] = {
  4734. r: (toColour.r - from[attr].r) / ms,
  4735. g: (toColour.g - from[attr].g) / ms,
  4736. b: (toColour.b - from[attr].b) / ms
  4737. };
  4738. break;
  4739. case "path":
  4740. var pathes = path2curve(from[attr], to[attr]),
  4741. toPath = pathes[1];
  4742. from[attr] = pathes[0];
  4743. diff[attr] = [];
  4744. for (i = 0, ii = from[attr].length; i < ii; i++) {
  4745. diff[attr][i] = [0];
  4746. for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
  4747. diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
  4748. }
  4749. }
  4750. break;
  4751. case "transform":
  4752. var _ = element._,
  4753. eq = equaliseTransform(_[attr], to[attr]);
  4754. if (eq) {
  4755. from[attr] = eq.from;
  4756. to[attr] = eq.to;
  4757. diff[attr] = [];
  4758. diff[attr].real = true;
  4759. for (i = 0, ii = from[attr].length; i < ii; i++) {
  4760. diff[attr][i] = [from[attr][i][0]];
  4761. for (j = 1, jj = from[attr][i].length; j < jj; j++) {
  4762. diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
  4763. }
  4764. }
  4765. } else {
  4766. var m = (element.matrix || new Matrix),
  4767. to2 = {
  4768. _: {transform: _.transform},
  4769. getBBox: function () {
  4770. return element.getBBox(1);
  4771. }
  4772. };
  4773. from[attr] = [
  4774. m.a,
  4775. m.b,
  4776. m.c,
  4777. m.d,
  4778. m.e,
  4779. m.f
  4780. ];
  4781. extractTransform(to2, to[attr]);
  4782. to[attr] = to2._.transform;
  4783. diff[attr] = [
  4784. (to2.matrix.a - m.a) / ms,
  4785. (to2.matrix.b - m.b) / ms,
  4786. (to2.matrix.c - m.c) / ms,
  4787. (to2.matrix.d - m.d) / ms,
  4788. (to2.matrix.e - m.e) / ms,
  4789. (to2.matrix.f - m.f) / ms
  4790. ];
  4791. // from[attr] = [_.sx, _.sy, _.deg, _.dx, _.dy];
  4792. // var to2 = {_:{}, getBBox: function () { return element.getBBox(); }};
  4793. // extractTransform(to2, to[attr]);
  4794. // diff[attr] = [
  4795. // (to2._.sx - _.sx) / ms,
  4796. // (to2._.sy - _.sy) / ms,
  4797. // (to2._.deg - _.deg) / ms,
  4798. // (to2._.dx - _.dx) / ms,
  4799. // (to2._.dy - _.dy) / ms
  4800. // ];
  4801. }
  4802. break;
  4803. case "csv":
  4804. var values = Str(params[attr])[split](separator),
  4805. from2 = Str(from[attr])[split](separator);
  4806. if (attr == "clip-rect") {
  4807. from[attr] = from2;
  4808. diff[attr] = [];
  4809. i = from2.length;
  4810. while (i--) {
  4811. diff[attr][i] = (values[i] - from[attr][i]) / ms;
  4812. }
  4813. }
  4814. to[attr] = values;
  4815. break;
  4816. default:
  4817. values = [][concat](params[attr]);
  4818. from2 = [][concat](from[attr]);
  4819. diff[attr] = [];
  4820. i = element.paper.customAttributes[attr].length;
  4821. while (i--) {
  4822. diff[attr][i] = ((values[i] || 0) - (from2[i] || 0)) / ms;
  4823. }
  4824. break;
  4825. }
  4826. }
  4827. }
  4828. var easing = params.easing,
  4829. easyeasy = R.easing_formulas[easing];
  4830. if (!easyeasy) {
  4831. easyeasy = Str(easing).match(bezierrg);
  4832. if (easyeasy && easyeasy.length == 5) {
  4833. var curve = easyeasy;
  4834. easyeasy = function (t) {
  4835. return CubicBezierAtTime(t, +curve[1], +curve[2], +curve[3], +curve[4], ms);
  4836. };
  4837. } else {
  4838. easyeasy = pipe;
  4839. }
  4840. }
  4841. timestamp = params.start || anim.start || +new Date;
  4842. e = {
  4843. anim: anim,
  4844. percent: percent,
  4845. timestamp: timestamp,
  4846. start: timestamp + (anim.del || 0),
  4847. status: 0,
  4848. initstatus: status || 0,
  4849. stop: false,
  4850. ms: ms,
  4851. easing: easyeasy,
  4852. from: from,
  4853. diff: diff,
  4854. to: to,
  4855. el: element,
  4856. callback: params.callback,
  4857. prev: prev,
  4858. next: next,
  4859. repeat: times || anim.times,
  4860. origin: element.attr(),
  4861. totalOrigin: totalOrigin
  4862. };
  4863. animationElements.push(e);
  4864. if (status && !isInAnim && !isInAnimSet) {
  4865. e.stop = true;
  4866. e.start = new Date - ms * status;
  4867. if (animationElements.length == 1) {
  4868. return animation();
  4869. }
  4870. }
  4871. if (isInAnimSet) {
  4872. e.start = new Date - e.ms * status;
  4873. }
  4874. animationElements.length == 1 && requestAnimFrame(animation);
  4875. } else {
  4876. isInAnim.initstatus = status;
  4877. isInAnim.start = new Date - isInAnim.ms * status;
  4878. }
  4879. eve("raphael.anim.start." + element.id, element, anim);
  4880. }
  4881. /*\
  4882. * Raphael.animation
  4883. [ method ]
  4884. **
  4885. * Creates an animation object that can be passed to the @Element.animate or @Element.animateWith methods.
  4886. * See also @Animation.delay and @Animation.repeat methods.
  4887. **
  4888. > Parameters
  4889. **
  4890. - params (object) final attributes for the element, see also @Element.attr
  4891. - ms (number) number of milliseconds for animation to run
  4892. - easing (string) #optional easing type. Accept one of @Raphael.easing_formulas or CSS format: `cubic&#x2010;bezier(XX,&#160;XX,&#160;XX,&#160;XX)`
  4893. - callback (function) #optional callback function. Will be called at the end of animation.
  4894. **
  4895. = (object) @Animation
  4896. \*/
  4897. R.animation = function (params, ms, easing, callback) {
  4898. if (params instanceof Animation) {
  4899. return params;
  4900. }
  4901. if (R.is(easing, "function") || !easing) {
  4902. callback = callback || easing || null;
  4903. easing = null;
  4904. }
  4905. params = Object(params);
  4906. ms = +ms || 0;
  4907. var p = {},
  4908. json,
  4909. attr;
  4910. for (attr in params) if (params[has](attr) && toFloat(attr) != attr && toFloat(attr) + "%" != attr) {
  4911. json = true;
  4912. p[attr] = params[attr];
  4913. }
  4914. if (!json) {
  4915. return new Animation(params, ms);
  4916. } else {
  4917. easing && (p.easing = easing);
  4918. callback && (p.callback = callback);
  4919. return new Animation({100: p}, ms);
  4920. }
  4921. };
  4922. /*\
  4923. * Element.animate
  4924. [ method ]
  4925. **
  4926. * Creates and starts animation for given element.
  4927. **
  4928. > Parameters
  4929. **
  4930. - params (object) final attributes for the element, see also @Element.attr
  4931. - ms (number) number of milliseconds for animation to run
  4932. - easing (string) #optional easing type. Accept one of @Raphael.easing_formulas or CSS format: `cubic&#x2010;bezier(XX,&#160;XX,&#160;XX,&#160;XX)`
  4933. - callback (function) #optional callback function. Will be called at the end of animation.
  4934. * or
  4935. - animation (object) animation object, see @Raphael.animation
  4936. **
  4937. = (object) original element
  4938. \*/
  4939. elproto.animate = function (params, ms, easing, callback) {
  4940. var element = this;
  4941. if (element.removed) {
  4942. callback && callback.call(element);
  4943. return element;
  4944. }
  4945. var anim = params instanceof Animation ? params : R.animation(params, ms, easing, callback);
  4946. runAnimation(anim, element, anim.percents[0], null, element.attr());
  4947. return element;
  4948. };
  4949. /*\
  4950. * Element.setTime
  4951. [ method ]
  4952. **
  4953. * Sets the status of animation of the element in milliseconds. Similar to @Element.status method.
  4954. **
  4955. > Parameters
  4956. **
  4957. - anim (object) animation object
  4958. - value (number) number of milliseconds from the beginning of the animation
  4959. **
  4960. = (object) original element if `value` is specified
  4961. * Note, that during animation following events are triggered:
  4962. *
  4963. * On each animation frame event `anim.frame.<id>`, on start `anim.start.<id>` and on end `anim.finish.<id>`.
  4964. \*/
  4965. elproto.setTime = function (anim, value) {
  4966. if (anim && value != null) {
  4967. this.status(anim, mmin(value, anim.ms) / anim.ms);
  4968. }
  4969. return this;
  4970. };
  4971. /*\
  4972. * Element.status
  4973. [ method ]
  4974. **
  4975. * Gets or sets the status of animation of the element.
  4976. **
  4977. > Parameters
  4978. **
  4979. - anim (object) #optional animation object
  4980. - value (number) #optional 0 – 1. If specified, method works like a setter and sets the status of a given animation to the value. This will cause animation to jump to the given position.
  4981. **
  4982. = (number) status
  4983. * or
  4984. = (array) status if `anim` is not specified. Array of objects in format:
  4985. o {
  4986. o anim: (object) animation object
  4987. o status: (number) status
  4988. o }
  4989. * or
  4990. = (object) original element if `value` is specified
  4991. \*/
  4992. elproto.status = function (anim, value) {
  4993. var out = [],
  4994. i = 0,
  4995. len,
  4996. e;
  4997. if (value != null) {
  4998. runAnimation(anim, this, -1, mmin(value, 1));
  4999. return this;
  5000. } else {
  5001. len = animationElements.length;
  5002. for (; i < len; i++) {
  5003. e = animationElements[i];
  5004. if (e.el.id == this.id && (!anim || e.anim == anim)) {
  5005. if (anim) {
  5006. return e.status;
  5007. }
  5008. out.push({
  5009. anim: e.anim,
  5010. status: e.status
  5011. });
  5012. }
  5013. }
  5014. if (anim) {
  5015. return 0;
  5016. }
  5017. return out;
  5018. }
  5019. };
  5020. /*\
  5021. * Element.pause
  5022. [ method ]
  5023. **
  5024. * Stops animation of the element with ability to resume it later on.
  5025. **
  5026. > Parameters
  5027. **
  5028. - anim (object) #optional animation object
  5029. **
  5030. = (object) original element
  5031. \*/
  5032. elproto.pause = function (anim) {
  5033. for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
  5034. if (eve("raphael.anim.pause." + this.id, this, animationElements[i].anim) !== false) {
  5035. animationElements[i].paused = true;
  5036. }
  5037. }
  5038. return this;
  5039. };
  5040. /*\
  5041. * Element.resume
  5042. [ method ]
  5043. **
  5044. * Resumes animation if it was paused with @Element.pause method.
  5045. **
  5046. > Parameters
  5047. **
  5048. - anim (object) #optional animation object
  5049. **
  5050. = (object) original element
  5051. \*/
  5052. elproto.resume = function (anim) {
  5053. for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
  5054. var e = animationElements[i];
  5055. if (eve("raphael.anim.resume." + this.id, this, e.anim) !== false) {
  5056. delete e.paused;
  5057. this.status(e.anim, e.status);
  5058. }
  5059. }
  5060. return this;
  5061. };
  5062. /*\
  5063. * Element.stop
  5064. [ method ]
  5065. **
  5066. * Stops animation of the element.
  5067. **
  5068. > Parameters
  5069. **
  5070. - anim (object) #optional animation object
  5071. **
  5072. = (object) original element
  5073. \*/
  5074. elproto.stop = function (anim) {
  5075. for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
  5076. if (eve("raphael.anim.stop." + this.id, this, animationElements[i].anim) !== false) {
  5077. animationElements.splice(i--, 1);
  5078. }
  5079. }
  5080. return this;
  5081. };
  5082. function stopAnimation(paper) {
  5083. for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.paper == paper) {
  5084. animationElements.splice(i--, 1);
  5085. }
  5086. }
  5087. eve.on("raphael.remove", stopAnimation);
  5088. eve.on("raphael.clear", stopAnimation);
  5089. elproto.toString = function () {
  5090. return "Rapha\xebl\u2019s object";
  5091. };
  5092. // Set
  5093. var Set = function (items) {
  5094. this.items = [];
  5095. this.length = 0;
  5096. this.type = "set";
  5097. if (items) {
  5098. for (var i = 0, ii = items.length; i < ii; i++) {
  5099. if (items[i] && (items[i].constructor == elproto.constructor || items[i].constructor == Set)) {
  5100. this[this.items.length] = this.items[this.items.length] = items[i];
  5101. this.length++;
  5102. }
  5103. }
  5104. }
  5105. },
  5106. setproto = Set.prototype;
  5107. /*\
  5108. * Set.push
  5109. [ method ]
  5110. **
  5111. * Adds each argument to the current set.
  5112. = (object) original element
  5113. \*/
  5114. setproto.push = function () {
  5115. var item,
  5116. len;
  5117. for (var i = 0, ii = arguments.length; i < ii; i++) {
  5118. item = arguments[i];
  5119. if (item && (item.constructor == elproto.constructor || item.constructor == Set)) {
  5120. len = this.items.length;
  5121. this[len] = this.items[len] = item;
  5122. this.length++;
  5123. }
  5124. }
  5125. return this;
  5126. };
  5127. /*\
  5128. * Set.pop
  5129. [ method ]
  5130. **
  5131. * Removes last element and returns it.
  5132. = (object) element
  5133. \*/
  5134. setproto.pop = function () {
  5135. this.length && delete this[this.length--];
  5136. return this.items.pop();
  5137. };
  5138. /*\
  5139. * Set.forEach
  5140. [ method ]
  5141. **
  5142. * Executes given function for each element in the set.
  5143. *
  5144. * If function returns `false` it will stop loop running.
  5145. **
  5146. > Parameters
  5147. **
  5148. - callback (function) function to run
  5149. - thisArg (object) context object for the callback
  5150. = (object) Set object
  5151. \*/
  5152. setproto.forEach = function (callback, thisArg) {
  5153. for (var i = 0, ii = this.items.length; i < ii; i++) {
  5154. if (callback.call(thisArg, this.items[i], i) === false) {
  5155. return this;
  5156. }
  5157. }
  5158. return this;
  5159. };
  5160. for (var method in elproto) if (elproto[has](method)) {
  5161. setproto[method] = (function (methodname) {
  5162. return function () {
  5163. var arg = arguments;
  5164. return this.forEach(function (el) {
  5165. el[methodname][apply](el, arg);
  5166. });
  5167. };
  5168. })(method);
  5169. }
  5170. setproto.attr = function (name, value) {
  5171. if (name && R.is(name, array) && R.is(name[0], "object")) {
  5172. for (var j = 0, jj = name.length; j < jj; j++) {
  5173. this.items[j].attr(name[j]);
  5174. }
  5175. } else {
  5176. for (var i = 0, ii = this.items.length; i < ii; i++) {
  5177. this.items[i].attr(name, value);
  5178. }
  5179. }
  5180. return this;
  5181. };
  5182. /*\
  5183. * Set.clear
  5184. [ method ]
  5185. **
  5186. * Removeds all elements from the set
  5187. \*/
  5188. setproto.clear = function () {
  5189. while (this.length) {
  5190. this.pop();
  5191. }
  5192. };
  5193. /*\
  5194. * Set.splice
  5195. [ method ]
  5196. **
  5197. * Removes given element from the set
  5198. **
  5199. > Parameters
  5200. **
  5201. - index (number) position of the deletion
  5202. - count (number) number of element to remove
  5203. - insertion… (object) #optional elements to insert
  5204. = (object) set elements that were deleted
  5205. \*/
  5206. setproto.splice = function (index, count, insertion) {
  5207. index = index < 0 ? mmax(this.length + index, 0) : index;
  5208. count = mmax(0, mmin(this.length - index, count));
  5209. var tail = [],
  5210. todel = [],
  5211. args = [],
  5212. i;
  5213. for (i = 2; i < arguments.length; i++) {
  5214. args.push(arguments[i]);
  5215. }
  5216. for (i = 0; i < count; i++) {
  5217. todel.push(this[index + i]);
  5218. }
  5219. for (; i < this.length - index; i++) {
  5220. tail.push(this[index + i]);
  5221. }
  5222. var arglen = args.length;
  5223. for (i = 0; i < arglen + tail.length; i++) {
  5224. this.items[index + i] = this[index + i] = i < arglen ? args[i] : tail[i - arglen];
  5225. }
  5226. i = this.items.length = this.length -= count - arglen;
  5227. while (this[i]) {
  5228. delete this[i++];
  5229. }
  5230. return new Set(todel);
  5231. };
  5232. /*\
  5233. * Set.exclude
  5234. [ method ]
  5235. **
  5236. * Removes given element from the set
  5237. **
  5238. > Parameters
  5239. **
  5240. - element (object) element to remove
  5241. = (boolean) `true` if object was found & removed from the set
  5242. \*/
  5243. setproto.exclude = function (el) {
  5244. for (var i = 0, ii = this.length; i < ii; i++) if (this[i] == el) {
  5245. this.splice(i, 1);
  5246. return true;
  5247. }
  5248. };
  5249. setproto.animate = function (params, ms, easing, callback) {
  5250. (R.is(easing, "function") || !easing) && (callback = easing || null);
  5251. var len = this.items.length,
  5252. i = len,
  5253. item,
  5254. set = this,
  5255. collector;
  5256. if (!len) {
  5257. return this;
  5258. }
  5259. callback && (collector = function () {
  5260. !--len && callback.call(set);
  5261. });
  5262. easing = R.is(easing, string) ? easing : collector;
  5263. var anim = R.animation(params, ms, easing, collector);
  5264. item = this.items[--i].animate(anim);
  5265. while (i--) {
  5266. this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, anim, anim);
  5267. (this.items[i] && !this.items[i].removed) || len--;
  5268. }
  5269. return this;
  5270. };
  5271. setproto.insertAfter = function (el) {
  5272. var i = this.items.length;
  5273. while (i--) {
  5274. this.items[i].insertAfter(el);
  5275. }
  5276. return this;
  5277. };
  5278. setproto.getBBox = function () {
  5279. var x = [],
  5280. y = [],
  5281. x2 = [],
  5282. y2 = [];
  5283. for (var i = this.items.length; i--;) if (!this.items[i].removed) {
  5284. var box = this.items[i].getBBox();
  5285. x.push(box.x);
  5286. y.push(box.y);
  5287. x2.push(box.x + box.width);
  5288. y2.push(box.y + box.height);
  5289. }
  5290. x = mmin[apply](0, x);
  5291. y = mmin[apply](0, y);
  5292. x2 = mmax[apply](0, x2);
  5293. y2 = mmax[apply](0, y2);
  5294. return {
  5295. x: x,
  5296. y: y,
  5297. x2: x2,
  5298. y2: y2,
  5299. width: x2 - x,
  5300. height: y2 - y
  5301. };
  5302. };
  5303. setproto.clone = function (s) {
  5304. s = this.paper.set();
  5305. for (var i = 0, ii = this.items.length; i < ii; i++) {
  5306. s.push(this.items[i].clone());
  5307. }
  5308. return s;
  5309. };
  5310. setproto.toString = function () {
  5311. return "Rapha\xebl\u2018s set";
  5312. };
  5313. setproto.glow = function(glowConfig) {
  5314. var ret = this.paper.set();
  5315. this.forEach(function(shape, index){
  5316. var g = shape.glow(glowConfig);
  5317. if(g != null){
  5318. g.forEach(function(shape2, index2){
  5319. ret.push(shape2);
  5320. });
  5321. }
  5322. });
  5323. return ret;
  5324. };
  5325. /*\
  5326. * Set.isPointInside
  5327. [ method ]
  5328. **
  5329. * Determine if given point is inside this set’s elements
  5330. **
  5331. > Parameters
  5332. **
  5333. - x (number) x coordinate of the point
  5334. - y (number) y coordinate of the point
  5335. = (boolean) `true` if point is inside any of the set's elements
  5336. \*/
  5337. setproto.isPointInside = function (x, y) {
  5338. var isPointInside = false;
  5339. this.forEach(function (el) {
  5340. if (el.isPointInside(x, y)) {
  5341. console.log('runned');
  5342. isPointInside = true;
  5343. return false; // stop loop
  5344. }
  5345. });
  5346. return isPointInside;
  5347. };
  5348. /*\
  5349. * Raphael.registerFont
  5350. [ method ]
  5351. **
  5352. * Adds given font to the registered set of fonts for Raphaël. Should be used as an internal call from within Cufón’s font file.
  5353. * Returns original parameter, so it could be used with chaining.
  5354. # <a href="http://wiki.github.com/sorccu/cufon/about">More about Cufón and how to convert your font form TTF, OTF, etc to JavaScript file.</a>
  5355. **
  5356. > Parameters
  5357. **
  5358. - font (object) the font to register
  5359. = (object) the font you passed in
  5360. > Usage
  5361. | Cufon.registerFont(Raphael.registerFont({…}));
  5362. \*/
  5363. R.registerFont = function (font) {
  5364. if (!font.face) {
  5365. return font;
  5366. }
  5367. this.fonts = this.fonts || {};
  5368. var fontcopy = {
  5369. w: font.w,
  5370. face: {},
  5371. glyphs: {}
  5372. },
  5373. family = font.face["font-family"];
  5374. for (var prop in font.face) if (font.face[has](prop)) {
  5375. fontcopy.face[prop] = font.face[prop];
  5376. }
  5377. if (this.fonts[family]) {
  5378. this.fonts[family].push(fontcopy);
  5379. } else {
  5380. this.fonts[family] = [fontcopy];
  5381. }
  5382. if (!font.svg) {
  5383. fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
  5384. for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
  5385. var path = font.glyphs[glyph];
  5386. fontcopy.glyphs[glyph] = {
  5387. w: path.w,
  5388. k: {},
  5389. d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
  5390. return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
  5391. }) + "z"
  5392. };
  5393. if (path.k) {
  5394. for (var k in path.k) if (path[has](k)) {
  5395. fontcopy.glyphs[glyph].k[k] = path.k[k];
  5396. }
  5397. }
  5398. }
  5399. }
  5400. return font;
  5401. };
  5402. /*\
  5403. * Paper.getFont
  5404. [ method ]
  5405. **
  5406. * Finds font object in the registered fonts by given parameters. You could specify only one word from the font name, like “Myriad” for “Myriad Pro”.
  5407. **
  5408. > Parameters
  5409. **
  5410. - family (string) font family name or any word from it
  5411. - weight (string) #optional font weight
  5412. - style (string) #optional font style
  5413. - stretch (string) #optional font stretch
  5414. = (object) the font object
  5415. > Usage
  5416. | paper.print(100, 100, "Test string", paper.getFont("Times", 800), 30);
  5417. \*/
  5418. paperproto.getFont = function (family, weight, style, stretch) {
  5419. stretch = stretch || "normal";
  5420. style = style || "normal";
  5421. weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
  5422. if (!R.fonts) {
  5423. return;
  5424. }
  5425. var font = R.fonts[family];
  5426. if (!font) {
  5427. var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
  5428. for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
  5429. if (name.test(fontName)) {
  5430. font = R.fonts[fontName];
  5431. break;
  5432. }
  5433. }
  5434. }
  5435. var thefont;
  5436. if (font) {
  5437. for (var i = 0, ii = font.length; i < ii; i++) {
  5438. thefont = font[i];
  5439. if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
  5440. break;
  5441. }
  5442. }
  5443. }
  5444. return thefont;
  5445. };
  5446. /*\
  5447. * Paper.print
  5448. [ method ]
  5449. **
  5450. * Creates path that represent given text written using given font at given position with given size.
  5451. * Result of the method is path element that contains whole text as a separate path.
  5452. **
  5453. > Parameters
  5454. **
  5455. - x (number) x position of the text
  5456. - y (number) y position of the text
  5457. - string (string) text to print
  5458. - font (object) font object, see @Paper.getFont
  5459. - size (number) #optional size of the font, default is `16`
  5460. - origin (string) #optional could be `"baseline"` or `"middle"`, default is `"middle"`
  5461. - letter_spacing (number) #optional number in range `-1..1`, default is `0`
  5462. - line_spacing (number) #optional number in range `1..3`, default is `1`
  5463. = (object) resulting path element, which consist of all letters
  5464. > Usage
  5465. | var txt = r.print(10, 50, "print", r.getFont("Museo"), 30).attr({fill: "#fff"});
  5466. \*/
  5467. paperproto.print = function (x, y, string, font, size, origin, letter_spacing, line_spacing) {
  5468. origin = origin || "middle"; // baseline|middle
  5469. letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1);
  5470. line_spacing = mmax(mmin(line_spacing || 1, 3), 1);
  5471. var letters = Str(string)[split](E),
  5472. shift = 0,
  5473. notfirst = 0,
  5474. path = E,
  5475. scale;
  5476. R.is(font, "string") && (font = this.getFont(font));
  5477. if (font) {
  5478. scale = (size || 16) / font.face["units-per-em"];
  5479. var bb = font.face.bbox[split](separator),
  5480. top = +bb[0],
  5481. lineHeight = bb[3] - bb[1],
  5482. shifty = 0,
  5483. height = +bb[1] + (origin == "baseline" ? lineHeight + (+font.face.descent) : lineHeight / 2);
  5484. for (var i = 0, ii = letters.length; i < ii; i++) {
  5485. if (letters[i] == "\n") {
  5486. shift = 0;
  5487. curr = 0;
  5488. notfirst = 0;
  5489. shifty += lineHeight * line_spacing;
  5490. } else {
  5491. var prev = notfirst && font.glyphs[letters[i - 1]] || {},
  5492. curr = font.glyphs[letters[i]];
  5493. shift += notfirst ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) + (font.w * letter_spacing) : 0;
  5494. notfirst = 1;
  5495. }
  5496. if (curr && curr.d) {
  5497. path += R.transformPath(curr.d, ["t", shift * scale, shifty * scale, "s", scale, scale, top, height, "t", (x - top) / scale, (y - height) / scale]);
  5498. }
  5499. }
  5500. }
  5501. return this.path(path).attr({
  5502. fill: "#000",
  5503. stroke: "none"
  5504. });
  5505. };
  5506. /*\
  5507. * Paper.add
  5508. [ method ]
  5509. **
  5510. * Imports elements in JSON array in format `{type: type, <attributes>}`
  5511. **
  5512. > Parameters
  5513. **
  5514. - json (array)
  5515. = (object) resulting set of imported elements
  5516. > Usage
  5517. | paper.add([
  5518. | {
  5519. | type: "circle",
  5520. | cx: 10,
  5521. | cy: 10,
  5522. | r: 5
  5523. | },
  5524. | {
  5525. | type: "rect",
  5526. | x: 10,
  5527. | y: 10,
  5528. | width: 10,
  5529. | height: 10,
  5530. | fill: "#fc0"
  5531. | }
  5532. | ]);
  5533. \*/
  5534. paperproto.add = function (json) {
  5535. if (R.is(json, "array")) {
  5536. var res = this.set(),
  5537. i = 0,
  5538. ii = json.length,
  5539. j;
  5540. for (; i < ii; i++) {
  5541. j = json[i] || {};
  5542. elements[has](j.type) && res.push(this[j.type]().attr(j));
  5543. }
  5544. }
  5545. return res;
  5546. };
  5547. /*\
  5548. * Raphael.format
  5549. [ method ]
  5550. **
  5551. * Simple format function. Replaces construction of type “`{<number>}`” to the corresponding argument.
  5552. **
  5553. > Parameters
  5554. **
  5555. - token (string) string to format
  5556. - … (string) rest of arguments will be treated as parameters for replacement
  5557. = (string) formated string
  5558. > Usage
  5559. | var x = 10,
  5560. | y = 20,
  5561. | width = 40,
  5562. | height = 50;
  5563. | // this will draw a rectangular shape equivalent to "M10,20h40v50h-40z"
  5564. | paper.path(Raphael.format("M{0},{1}h{2}v{3}h{4}z", x, y, width, height, -width));
  5565. \*/
  5566. R.format = function (token, params) {
  5567. var args = R.is(params, array) ? [0][concat](params) : arguments;
  5568. token && R.is(token, string) && args.length - 1 && (token = token.replace(formatrg, function (str, i) {
  5569. return args[++i] == null ? E : args[i];
  5570. }));
  5571. return token || E;
  5572. };
  5573. /*\
  5574. * Raphael.fullfill
  5575. [ method ]
  5576. **
  5577. * A little bit more advanced format function than @Raphael.format. Replaces construction of type “`{<name>}`” to the corresponding argument.
  5578. **
  5579. > Parameters
  5580. **
  5581. - token (string) string to format
  5582. - json (object) object which properties will be used as a replacement
  5583. = (string) formated string
  5584. > Usage
  5585. | // this will draw a rectangular shape equivalent to "M10,20h40v50h-40z"
  5586. | paper.path(Raphael.fullfill("M{x},{y}h{dim.width}v{dim.height}h{dim['negative width']}z", {
  5587. | x: 10,
  5588. | y: 20,
  5589. | dim: {
  5590. | width: 40,
  5591. | height: 50,
  5592. | "negative width": -40
  5593. | }
  5594. | }));
  5595. \*/
  5596. R.fullfill = (function () {
  5597. var tokenRegex = /\{([^\}]+)\}/g,
  5598. objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g, // matches .xxxxx or ["xxxxx"] to run over object properties
  5599. replacer = function (all, key, obj) {
  5600. var res = obj;
  5601. key.replace(objNotationRegex, function (all, name, quote, quotedName, isFunc) {
  5602. name = name || quotedName;
  5603. if (res) {
  5604. if (name in res) {
  5605. res = res[name];
  5606. }
  5607. typeof res == "function" && isFunc && (res = res());
  5608. }
  5609. });
  5610. res = (res == null || res == obj ? all : res) + "";
  5611. return res;
  5612. };
  5613. return function (str, obj) {
  5614. return String(str).replace(tokenRegex, function (all, key) {
  5615. return replacer(all, key, obj);
  5616. });
  5617. };
  5618. })();
  5619. /*\
  5620. * Raphael.ninja
  5621. [ method ]
  5622. **
  5623. * If you want to leave no trace of Raphaël (Well, Raphaël creates only one global variable `Raphael`, but anyway.) You can use `ninja` method.
  5624. * Beware, that in this case plugins could stop working, because they are depending on global variable existance.
  5625. **
  5626. = (object) Raphael object
  5627. > Usage
  5628. | (function (local_raphael) {
  5629. | var paper = local_raphael(10, 10, 320, 200);
  5630. | …
  5631. | })(Raphael.ninja());
  5632. \*/
  5633. R.ninja = function () {
  5634. oldRaphael.was ? (g.win.Raphael = oldRaphael.is) : delete Raphael;
  5635. return R;
  5636. };
  5637. /*\
  5638. * Raphael.st
  5639. [ property (object) ]
  5640. **
  5641. * You can add your own method to elements and sets. It is wise to add a set method for each element method
  5642. * you added, so you will be able to call the same method on sets too.
  5643. **
  5644. * See also @Raphael.el.
  5645. > Usage
  5646. | Raphael.el.red = function () {
  5647. | this.attr({fill: "#f00"});
  5648. | };
  5649. | Raphael.st.red = function () {
  5650. | this.forEach(function (el) {
  5651. | el.red();
  5652. | });
  5653. | };
  5654. | // then use it
  5655. | paper.set(paper.circle(100, 100, 20), paper.circle(110, 100, 20)).red();
  5656. \*/
  5657. R.st = setproto;
  5658. // Firefox <3.6 fix: http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
  5659. (function (doc, loaded, f) {
  5660. if (doc.readyState == null && doc.addEventListener){
  5661. doc.addEventListener(loaded, f = function () {
  5662. doc.removeEventListener(loaded, f, false);
  5663. doc.readyState = "complete";
  5664. }, false);
  5665. doc.readyState = "loading";
  5666. }
  5667. function isLoaded() {
  5668. (/in/).test(doc.readyState) ? setTimeout(isLoaded, 9) : R.eve("raphael.DOMload");
  5669. }
  5670. isLoaded();
  5671. })(document, "DOMContentLoaded");
  5672. eve.on("raphael.DOMload", function () {
  5673. loaded = true;
  5674. });
  5675. // ┌─────────────────────────────────────────────────────────────────────┐ \\
  5676. // │ Raphaël - JavaScript Vector Library │ \\
  5677. // ├─────────────────────────────────────────────────────────────────────┤ \\
  5678. // │ SVG Module │ \\
  5679. // ├─────────────────────────────────────────────────────────────────────┤ \\
  5680. // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
  5681. // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
  5682. // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
  5683. // └─────────────────────────────────────────────────────────────────────┘ \\
  5684. (function(){
  5685. if (!R.svg) {
  5686. return;
  5687. }
  5688. var has = "hasOwnProperty",
  5689. Str = String,
  5690. toFloat = parseFloat,
  5691. toInt = parseInt,
  5692. math = Math,
  5693. mmax = math.max,
  5694. abs = math.abs,
  5695. pow = math.pow,
  5696. separator = /[, ]+/,
  5697. eve = R.eve,
  5698. E = "",
  5699. S = " ";
  5700. var xlink = "http://www.w3.org/1999/xlink",
  5701. markers = {
  5702. block: "M5,0 0,2.5 5,5z",
  5703. classic: "M5,0 0,2.5 5,5 3.5,3 3.5,2z",
  5704. diamond: "M2.5,0 5,2.5 2.5,5 0,2.5z",
  5705. open: "M6,1 1,3.5 6,6",
  5706. oval: "M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"
  5707. },
  5708. markerCounter = {};
  5709. R.toString = function () {
  5710. return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
  5711. };
  5712. var $ = function (el, attr) {
  5713. if (attr) {
  5714. if (typeof el == "string") {
  5715. el = $(el);
  5716. }
  5717. for (var key in attr) if (attr[has](key)) {
  5718. if (key.substring(0, 6) == "xlink:") {
  5719. el.setAttributeNS(xlink, key.substring(6), Str(attr[key]));
  5720. } else {
  5721. el.setAttribute(key, Str(attr[key]));
  5722. }
  5723. }
  5724. } else {
  5725. el = R._g.doc.createElementNS("http://www.w3.org/2000/svg", el);
  5726. el.style && (el.style.webkitTapHighlightColor = "rgba(0,0,0,0)");
  5727. }
  5728. return el;
  5729. },
  5730. addGradientFill = function (element, gradient) {
  5731. var type = "linear",
  5732. id = element.id + gradient,
  5733. fx = .5, fy = .5,
  5734. o = element.node,
  5735. SVG = element.paper,
  5736. s = o.style,
  5737. el = R._g.doc.getElementById(id);
  5738. if (!el) {
  5739. gradient = Str(gradient).replace(R._radial_gradient, function (all, _fx, _fy) {
  5740. type = "radial";
  5741. if (_fx && _fy) {
  5742. fx = toFloat(_fx);
  5743. fy = toFloat(_fy);
  5744. var dir = ((fy > .5) * 2 - 1);
  5745. pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
  5746. (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
  5747. fy != .5 &&
  5748. (fy = fy.toFixed(5) - 1e-5 * dir);
  5749. }
  5750. return E;
  5751. });
  5752. gradient = gradient.split(/\s*\-\s*/);
  5753. if (type == "linear") {
  5754. var angle = gradient.shift();
  5755. angle = -toFloat(angle);
  5756. if (isNaN(angle)) {
  5757. return null;
  5758. }
  5759. var vector = [0, 0, math.cos(R.rad(angle)), math.sin(R.rad(angle))],
  5760. max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
  5761. vector[2] *= max;
  5762. vector[3] *= max;
  5763. if (vector[2] < 0) {
  5764. vector[0] = -vector[2];
  5765. vector[2] = 0;
  5766. }
  5767. if (vector[3] < 0) {
  5768. vector[1] = -vector[3];
  5769. vector[3] = 0;
  5770. }
  5771. }
  5772. var dots = R._parseDots(gradient);
  5773. if (!dots) {
  5774. return null;
  5775. }
  5776. id = id.replace(/[\(\)\s,\xb0#]/g, "_");
  5777. if (element.gradient && id != element.gradient.id) {
  5778. SVG.defs.removeChild(element.gradient);
  5779. delete element.gradient;
  5780. }
  5781. if (!element.gradient) {
  5782. el = $(type + "Gradient", {id: id});
  5783. element.gradient = el;
  5784. $(el, type == "radial" ? {
  5785. fx: fx,
  5786. fy: fy
  5787. } : {
  5788. x1: vector[0],
  5789. y1: vector[1],
  5790. x2: vector[2],
  5791. y2: vector[3],
  5792. gradientTransform: element.matrix.invert()
  5793. });
  5794. SVG.defs.appendChild(el);
  5795. for (var i = 0, ii = dots.length; i < ii; i++) {
  5796. el.appendChild($("stop", {
  5797. offset: dots[i].offset ? dots[i].offset : i ? "100%" : "0%",
  5798. "stop-color": dots[i].color || "#fff"
  5799. }));
  5800. }
  5801. }
  5802. }
  5803. $(o, {
  5804. fill: "url(#" + id + ")",
  5805. opacity: 1,
  5806. "fill-opacity": 1
  5807. });
  5808. s.fill = E;
  5809. s.opacity = 1;
  5810. s.fillOpacity = 1;
  5811. return 1;
  5812. },
  5813. updatePosition = function (o) {
  5814. var bbox = o.getBBox(1);
  5815. $(o.pattern, {patternTransform: o.matrix.invert() + " translate(" + bbox.x + "," + bbox.y + ")"});
  5816. },
  5817. addArrow = function (o, value, isEnd) {
  5818. if (o.type == "path") {
  5819. var values = Str(value).toLowerCase().split("-"),
  5820. p = o.paper,
  5821. se = isEnd ? "end" : "start",
  5822. node = o.node,
  5823. attrs = o.attrs,
  5824. stroke = attrs["stroke-width"],
  5825. i = values.length,
  5826. type = "classic",
  5827. from,
  5828. to,
  5829. dx,
  5830. refX,
  5831. attr,
  5832. w = 3,
  5833. h = 3,
  5834. t = 5;
  5835. while (i--) {
  5836. switch (values[i]) {
  5837. case "block":
  5838. case "classic":
  5839. case "oval":
  5840. case "diamond":
  5841. case "open":
  5842. case "none":
  5843. type = values[i];
  5844. break;
  5845. case "wide": h = 5; break;
  5846. case "narrow": h = 2; break;
  5847. case "long": w = 5; break;
  5848. case "short": w = 2; break;
  5849. }
  5850. }
  5851. if (type == "open") {
  5852. w += 2;
  5853. h += 2;
  5854. t += 2;
  5855. dx = 1;
  5856. refX = isEnd ? 4 : 1;
  5857. attr = {
  5858. fill: "none",
  5859. stroke: attrs.stroke
  5860. };
  5861. } else {
  5862. refX = dx = w / 2;
  5863. attr = {
  5864. fill: attrs.stroke,
  5865. stroke: "none"
  5866. };
  5867. }
  5868. if (o._.arrows) {
  5869. if (isEnd) {
  5870. o._.arrows.endPath && markerCounter[o._.arrows.endPath]--;
  5871. o._.arrows.endMarker && markerCounter[o._.arrows.endMarker]--;
  5872. } else {
  5873. o._.arrows.startPath && markerCounter[o._.arrows.startPath]--;
  5874. o._.arrows.startMarker && markerCounter[o._.arrows.startMarker]--;
  5875. }
  5876. } else {
  5877. o._.arrows = {};
  5878. }
  5879. if (type != "none") {
  5880. var pathId = "raphael-marker-" + type,
  5881. markerId = "raphael-marker-" + se + type + w + h;
  5882. if (!R._g.doc.getElementById(pathId)) {
  5883. p.defs.appendChild($($("path"), {
  5884. "stroke-linecap": "round",
  5885. d: markers[type],
  5886. id: pathId
  5887. }));
  5888. markerCounter[pathId] = 1;
  5889. } else {
  5890. markerCounter[pathId]++;
  5891. }
  5892. var marker = R._g.doc.getElementById(markerId),
  5893. use;
  5894. if (!marker) {
  5895. marker = $($("marker"), {
  5896. id: markerId,
  5897. markerHeight: h,
  5898. markerWidth: w,
  5899. orient: "auto",
  5900. refX: refX,
  5901. refY: h / 2
  5902. });
  5903. use = $($("use"), {
  5904. "xlink:href": "#" + pathId,
  5905. transform: (isEnd ? "rotate(180 " + w / 2 + " " + h / 2 + ") " : E) + "scale(" + w / t + "," + h / t + ")",
  5906. "stroke-width": (1 / ((w / t + h / t) / 2)).toFixed(4)
  5907. });
  5908. marker.appendChild(use);
  5909. p.defs.appendChild(marker);
  5910. markerCounter[markerId] = 1;
  5911. } else {
  5912. markerCounter[markerId]++;
  5913. use = marker.getElementsByTagName("use")[0];
  5914. }
  5915. $(use, attr);
  5916. var delta = dx * (type != "diamond" && type != "oval");
  5917. if (isEnd) {
  5918. from = o._.arrows.startdx * stroke || 0;
  5919. to = R.getTotalLength(attrs.path) - delta * stroke;
  5920. } else {
  5921. from = delta * stroke;
  5922. to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
  5923. }
  5924. attr = {};
  5925. attr["marker-" + se] = "url(#" + markerId + ")";
  5926. if (to || from) {
  5927. attr.d = R.getSubpath(attrs.path, from, to);
  5928. }
  5929. $(node, attr);
  5930. o._.arrows[se + "Path"] = pathId;
  5931. o._.arrows[se + "Marker"] = markerId;
  5932. o._.arrows[se + "dx"] = delta;
  5933. o._.arrows[se + "Type"] = type;
  5934. o._.arrows[se + "String"] = value;
  5935. } else {
  5936. if (isEnd) {
  5937. from = o._.arrows.startdx * stroke || 0;
  5938. to = R.getTotalLength(attrs.path) - from;
  5939. } else {
  5940. from = 0;
  5941. to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
  5942. }
  5943. o._.arrows[se + "Path"] && $(node, {d: R.getSubpath(attrs.path, from, to)});
  5944. delete o._.arrows[se + "Path"];
  5945. delete o._.arrows[se + "Marker"];
  5946. delete o._.arrows[se + "dx"];
  5947. delete o._.arrows[se + "Type"];
  5948. delete o._.arrows[se + "String"];
  5949. }
  5950. for (attr in markerCounter) if (markerCounter[has](attr) && !markerCounter[attr]) {
  5951. var item = R._g.doc.getElementById(attr);
  5952. item && item.parentNode.removeChild(item);
  5953. }
  5954. }
  5955. },
  5956. dasharray = {
  5957. "": [0],
  5958. "none": [0],
  5959. "-": [3, 1],
  5960. ".": [1, 1],
  5961. "-.": [3, 1, 1, 1],
  5962. "-..": [3, 1, 1, 1, 1, 1],
  5963. ". ": [1, 3],
  5964. "- ": [4, 3],
  5965. "--": [8, 3],
  5966. "- .": [4, 3, 1, 3],
  5967. "--.": [8, 3, 1, 3],
  5968. "--..": [8, 3, 1, 3, 1, 3]
  5969. },
  5970. addDashes = function (o, value, params) {
  5971. value = dasharray[Str(value).toLowerCase()];
  5972. if (value) {
  5973. var width = o.attrs["stroke-width"] || "1",
  5974. butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
  5975. dashes = [],
  5976. i = value.length;
  5977. while (i--) {
  5978. dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
  5979. }
  5980. $(o.node, {"stroke-dasharray": dashes.join(",")});
  5981. }
  5982. },
  5983. setFillAndStroke = function (o, params) {
  5984. var node = o.node,
  5985. attrs = o.attrs,
  5986. vis = node.style.visibility;
  5987. node.style.visibility = "hidden";
  5988. for (var att in params) {
  5989. if (params[has](att)) {
  5990. if (!R._availableAttrs[has](att)) {
  5991. continue;
  5992. }
  5993. var value = params[att];
  5994. attrs[att] = value;
  5995. switch (att) {
  5996. case "blur":
  5997. o.blur(value);
  5998. break;
  5999. case "href":
  6000. case "title":
  6001. var hl = $("title");
  6002. var val = R._g.doc.createTextNode(value);
  6003. hl.appendChild(val);
  6004. node.appendChild(hl);
  6005. break;
  6006. case "target":
  6007. var pn = node.parentNode;
  6008. if (pn.tagName.toLowerCase() != "a") {
  6009. var hl = $("a");
  6010. pn.insertBefore(hl, node);
  6011. hl.appendChild(node);
  6012. pn = hl;
  6013. }
  6014. if (att == "target") {
  6015. pn.setAttributeNS(xlink, "show", value == "blank" ? "new" : value);
  6016. } else {
  6017. pn.setAttributeNS(xlink, att, value);
  6018. }
  6019. break;
  6020. case "cursor":
  6021. node.style.cursor = value;
  6022. break;
  6023. case "transform":
  6024. o.transform(value);
  6025. break;
  6026. case "arrow-start":
  6027. addArrow(o, value);
  6028. break;
  6029. case "arrow-end":
  6030. addArrow(o, value, 1);
  6031. break;
  6032. case "clip-rect":
  6033. var rect = Str(value).split(separator);
  6034. if (rect.length == 4) {
  6035. o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
  6036. var el = $("clipPath"),
  6037. rc = $("rect");
  6038. el.id = R.createUUID();
  6039. $(rc, {
  6040. x: rect[0],
  6041. y: rect[1],
  6042. width: rect[2],
  6043. height: rect[3]
  6044. });
  6045. el.appendChild(rc);
  6046. o.paper.defs.appendChild(el);
  6047. $(node, {"clip-path": "url(#" + el.id + ")"});
  6048. o.clip = rc;
  6049. }
  6050. if (!value) {
  6051. var path = node.getAttribute("clip-path");
  6052. if (path) {
  6053. var clip = R._g.doc.getElementById(path.replace(/(^url\(#|\)$)/g, E));
  6054. clip && clip.parentNode.removeChild(clip);
  6055. $(node, {"clip-path": E});
  6056. delete o.clip;
  6057. }
  6058. }
  6059. break;
  6060. case "path":
  6061. if (o.type == "path") {
  6062. $(node, {d: value ? attrs.path = R._pathToAbsolute(value) : "M0,0"});
  6063. o._.dirty = 1;
  6064. if (o._.arrows) {
  6065. "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
  6066. "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
  6067. }
  6068. }
  6069. break;
  6070. case "width":
  6071. node.setAttribute(att, value);
  6072. o._.dirty = 1;
  6073. if (attrs.fx) {
  6074. att = "x";
  6075. value = attrs.x;
  6076. } else {
  6077. break;
  6078. }
  6079. case "x":
  6080. if (attrs.fx) {
  6081. value = -attrs.x - (attrs.width || 0);
  6082. }
  6083. case "rx":
  6084. if (att == "rx" && o.type == "rect") {
  6085. break;
  6086. }
  6087. case "cx":
  6088. node.setAttribute(att, value);
  6089. o.pattern && updatePosition(o);
  6090. o._.dirty = 1;
  6091. break;
  6092. case "height":
  6093. node.setAttribute(att, value);
  6094. o._.dirty = 1;
  6095. if (attrs.fy) {
  6096. att = "y";
  6097. value = attrs.y;
  6098. } else {
  6099. break;
  6100. }
  6101. case "y":
  6102. if (attrs.fy) {
  6103. value = -attrs.y - (attrs.height || 0);
  6104. }
  6105. case "ry":
  6106. if (att == "ry" && o.type == "rect") {
  6107. break;
  6108. }
  6109. case "cy":
  6110. node.setAttribute(att, value);
  6111. o.pattern && updatePosition(o);
  6112. o._.dirty = 1;
  6113. break;
  6114. case "r":
  6115. if (o.type == "rect") {
  6116. $(node, {rx: value, ry: value});
  6117. } else {
  6118. node.setAttribute(att, value);
  6119. }
  6120. o._.dirty = 1;
  6121. break;
  6122. case "src":
  6123. if (o.type == "image") {
  6124. node.setAttributeNS(xlink, "href", value);
  6125. }
  6126. break;
  6127. case "stroke-width":
  6128. if (o._.sx != 1 || o._.sy != 1) {
  6129. value /= mmax(abs(o._.sx), abs(o._.sy)) || 1;
  6130. }
  6131. if (o.paper._vbSize) {
  6132. value *= o.paper._vbSize;
  6133. }
  6134. node.setAttribute(att, value);
  6135. if (attrs["stroke-dasharray"]) {
  6136. addDashes(o, attrs["stroke-dasharray"], params);
  6137. }
  6138. if (o._.arrows) {
  6139. "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
  6140. "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
  6141. }
  6142. break;
  6143. case "stroke-dasharray":
  6144. addDashes(o, value, params);
  6145. break;
  6146. case "fill":
  6147. var isURL = Str(value).match(R._ISURL);
  6148. if (isURL) {
  6149. el = $("pattern");
  6150. var ig = $("image");
  6151. el.id = R.createUUID();
  6152. $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
  6153. $(ig, {x: 0, y: 0, "xlink:href": isURL[1]});
  6154. el.appendChild(ig);
  6155. (function (el) {
  6156. R._preload(isURL[1], function () {
  6157. var w = this.offsetWidth,
  6158. h = this.offsetHeight;
  6159. $(el, {width: w, height: h});
  6160. $(ig, {width: w, height: h});
  6161. o.paper.safari();
  6162. });
  6163. })(el);
  6164. o.paper.defs.appendChild(el);
  6165. $(node, {fill: "url(#" + el.id + ")"});
  6166. o.pattern = el;
  6167. o.pattern && updatePosition(o);
  6168. break;
  6169. }
  6170. var clr = R.getRGB(value);
  6171. if (!clr.error) {
  6172. delete params.gradient;
  6173. delete attrs.gradient;
  6174. !R.is(attrs.opacity, "undefined") &&
  6175. R.is(params.opacity, "undefined") &&
  6176. $(node, {opacity: attrs.opacity});
  6177. !R.is(attrs["fill-opacity"], "undefined") &&
  6178. R.is(params["fill-opacity"], "undefined") &&
  6179. $(node, {"fill-opacity": attrs["fill-opacity"]});
  6180. } else if ((o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value)) {
  6181. if ("opacity" in attrs || "fill-opacity" in attrs) {
  6182. var gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
  6183. if (gradient) {
  6184. var stops = gradient.getElementsByTagName("stop");
  6185. $(stops[stops.length - 1], {"stop-opacity": ("opacity" in attrs ? attrs.opacity : 1) * ("fill-opacity" in attrs ? attrs["fill-opacity"] : 1)});
  6186. }
  6187. }
  6188. attrs.gradient = value;
  6189. attrs.fill = "none";
  6190. break;
  6191. }
  6192. clr[has]("opacity") && $(node, {"fill-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
  6193. case "stroke":
  6194. clr = R.getRGB(value);
  6195. node.setAttribute(att, clr.hex);
  6196. att == "stroke" && clr[has]("opacity") && $(node, {"stroke-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
  6197. if (att == "stroke" && o._.arrows) {
  6198. "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
  6199. "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
  6200. }
  6201. break;
  6202. case "gradient":
  6203. (o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value);
  6204. break;
  6205. case "opacity":
  6206. if (attrs.gradient && !attrs[has]("stroke-opacity")) {
  6207. $(node, {"stroke-opacity": value > 1 ? value / 100 : value});
  6208. }
  6209. // fall
  6210. case "fill-opacity":
  6211. if (attrs.gradient) {
  6212. gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
  6213. if (gradient) {
  6214. stops = gradient.getElementsByTagName("stop");
  6215. $(stops[stops.length - 1], {"stop-opacity": value});
  6216. }
  6217. break;
  6218. }
  6219. default:
  6220. att == "font-size" && (value = toInt(value, 10) + "px");
  6221. var cssrule = att.replace(/(\-.)/g, function (w) {
  6222. return w.substring(1).toUpperCase();
  6223. });
  6224. node.style[cssrule] = value;
  6225. o._.dirty = 1;
  6226. node.setAttribute(att, value);
  6227. break;
  6228. }
  6229. }
  6230. }
  6231. tuneText(o, params);
  6232. node.style.visibility = vis;
  6233. },
  6234. leading = 1.2,
  6235. tuneText = function (el, params) {
  6236. if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
  6237. return;
  6238. }
  6239. var a = el.attrs,
  6240. node = el.node,
  6241. fontSize = node.firstChild ? toInt(R._g.doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
  6242. if (params[has]("text")) {
  6243. a.text = params.text;
  6244. while (node.firstChild) {
  6245. node.removeChild(node.firstChild);
  6246. }
  6247. var texts = Str(params.text).split("\n"),
  6248. tspans = [],
  6249. tspan;
  6250. for (var i = 0, ii = texts.length; i < ii; i++) {
  6251. tspan = $("tspan");
  6252. i && $(tspan, {dy: fontSize * leading, x: a.x});
  6253. tspan.appendChild(R._g.doc.createTextNode(texts[i]));
  6254. node.appendChild(tspan);
  6255. tspans[i] = tspan;
  6256. }
  6257. } else {
  6258. tspans = node.getElementsByTagName("tspan");
  6259. for (i = 0, ii = tspans.length; i < ii; i++) if (i) {
  6260. $(tspans[i], {dy: fontSize * leading, x: a.x});
  6261. } else {
  6262. $(tspans[0], {dy: 0});
  6263. }
  6264. }
  6265. $(node, {x: a.x, y: a.y});
  6266. el._.dirty = 1;
  6267. var bb = el._getBBox(),
  6268. dif = a.y - (bb.y + bb.height / 2);
  6269. dif && R.is(dif, "finite") && $(tspans[0], {dy: dif});
  6270. },
  6271. Element = function (node, svg) {
  6272. var X = 0,
  6273. Y = 0;
  6274. /*\
  6275. * Element.node
  6276. [ property (object) ]
  6277. **
  6278. * Gives you a reference to the DOM object, so you can assign event handlers or just mess around.
  6279. **
  6280. * Note: Don’t mess with it.
  6281. > Usage
  6282. | // draw a circle at coordinate 10,10 with radius of 10
  6283. | var c = paper.circle(10, 10, 10);
  6284. | c.node.onclick = function () {
  6285. | c.attr("fill", "red");
  6286. | };
  6287. \*/
  6288. this[0] = this.node = node;
  6289. /*\
  6290. * Element.raphael
  6291. [ property (object) ]
  6292. **
  6293. * Internal reference to @Raphael object. In case it is not available.
  6294. > Usage
  6295. | Raphael.el.red = function () {
  6296. | var hsb = this.paper.raphael.rgb2hsb(this.attr("fill"));
  6297. | hsb.h = 1;
  6298. | this.attr({fill: this.paper.raphael.hsb2rgb(hsb).hex});
  6299. | }
  6300. \*/
  6301. node.raphael = true;
  6302. /*\
  6303. * Element.id
  6304. [ property (number) ]
  6305. **
  6306. * Unique id of the element. Especially usesful when you want to listen to events of the element,
  6307. * because all events are fired in format `<module>.<action>.<id>`. Also useful for @Paper.getById method.
  6308. \*/
  6309. this.id = R._oid++;
  6310. node.raphaelid = this.id;
  6311. this.matrix = R.matrix();
  6312. this.realPath = null;
  6313. /*\
  6314. * Element.paper
  6315. [ property (object) ]
  6316. **
  6317. * Internal reference to “paper” where object drawn. Mainly for use in plugins and element extensions.
  6318. > Usage
  6319. | Raphael.el.cross = function () {
  6320. | this.attr({fill: "red"});
  6321. | this.paper.path("M10,10L50,50M50,10L10,50")
  6322. | .attr({stroke: "red"});
  6323. | }
  6324. \*/
  6325. this.paper = svg;
  6326. this.attrs = this.attrs || {};
  6327. this._ = {
  6328. transform: [],
  6329. sx: 1,
  6330. sy: 1,
  6331. deg: 0,
  6332. dx: 0,
  6333. dy: 0,
  6334. dirty: 1
  6335. };
  6336. !svg.bottom && (svg.bottom = this);
  6337. /*\
  6338. * Element.prev
  6339. [ property (object) ]
  6340. **
  6341. * Reference to the previous element in the hierarchy.
  6342. \*/
  6343. this.prev = svg.top;
  6344. svg.top && (svg.top.next = this);
  6345. svg.top = this;
  6346. /*\
  6347. * Element.next
  6348. [ property (object) ]
  6349. **
  6350. * Reference to the next element in the hierarchy.
  6351. \*/
  6352. this.next = null;
  6353. },
  6354. elproto = R.el;
  6355. Element.prototype = elproto;
  6356. elproto.constructor = Element;
  6357. R._engine.path = function (pathString, SVG) {
  6358. var el = $("path");
  6359. SVG.canvas && SVG.canvas.appendChild(el);
  6360. var p = new Element(el, SVG);
  6361. p.type = "path";
  6362. setFillAndStroke(p, {
  6363. fill: "none",
  6364. stroke: "#000",
  6365. path: pathString
  6366. });
  6367. return p;
  6368. };
  6369. /*\
  6370. * Element.rotate
  6371. [ method ]
  6372. **
  6373. * Deprecated! Use @Element.transform instead.
  6374. * Adds rotation by given angle around given point to the list of
  6375. * transformations of the element.
  6376. > Parameters
  6377. - deg (number) angle in degrees
  6378. - cx (number) #optional x coordinate of the centre of rotation
  6379. - cy (number) #optional y coordinate of the centre of rotation
  6380. * If cx & cy aren’t specified centre of the shape is used as a point of rotation.
  6381. = (object) @Element
  6382. \*/
  6383. elproto.rotate = function (deg, cx, cy) {
  6384. if (this.removed) {
  6385. return this;
  6386. }
  6387. deg = Str(deg).split(separator);
  6388. if (deg.length - 1) {
  6389. cx = toFloat(deg[1]);
  6390. cy = toFloat(deg[2]);
  6391. }
  6392. deg = toFloat(deg[0]);
  6393. (cy == null) && (cx = cy);
  6394. if (cx == null || cy == null) {
  6395. var bbox = this.getBBox(1);
  6396. cx = bbox.x + bbox.width / 2;
  6397. cy = bbox.y + bbox.height / 2;
  6398. }
  6399. this.transform(this._.transform.concat([["r", deg, cx, cy]]));
  6400. return this;
  6401. };
  6402. /*\
  6403. * Element.scale
  6404. [ method ]
  6405. **
  6406. * Deprecated! Use @Element.transform instead.
  6407. * Adds scale by given amount relative to given point to the list of
  6408. * transformations of the element.
  6409. > Parameters
  6410. - sx (number) horisontal scale amount
  6411. - sy (number) vertical scale amount
  6412. - cx (number) #optional x coordinate of the centre of scale
  6413. - cy (number) #optional y coordinate of the centre of scale
  6414. * If cx & cy aren’t specified centre of the shape is used instead.
  6415. = (object) @Element
  6416. \*/
  6417. elproto.scale = function (sx, sy, cx, cy) {
  6418. if (this.removed) {
  6419. return this;
  6420. }
  6421. sx = Str(sx).split(separator);
  6422. if (sx.length - 1) {
  6423. sy = toFloat(sx[1]);
  6424. cx = toFloat(sx[2]);
  6425. cy = toFloat(sx[3]);
  6426. }
  6427. sx = toFloat(sx[0]);
  6428. (sy == null) && (sy = sx);
  6429. (cy == null) && (cx = cy);
  6430. if (cx == null || cy == null) {
  6431. var bbox = this.getBBox(1);
  6432. }
  6433. cx = cx == null ? bbox.x + bbox.width / 2 : cx;
  6434. cy = cy == null ? bbox.y + bbox.height / 2 : cy;
  6435. this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
  6436. return this;
  6437. };
  6438. /*\
  6439. * Element.translate
  6440. [ method ]
  6441. **
  6442. * Deprecated! Use @Element.transform instead.
  6443. * Adds translation by given amount to the list of transformations of the element.
  6444. > Parameters
  6445. - dx (number) horisontal shift
  6446. - dy (number) vertical shift
  6447. = (object) @Element
  6448. \*/
  6449. elproto.translate = function (dx, dy) {
  6450. if (this.removed) {
  6451. return this;
  6452. }
  6453. dx = Str(dx).split(separator);
  6454. if (dx.length - 1) {
  6455. dy = toFloat(dx[1]);
  6456. }
  6457. dx = toFloat(dx[0]) || 0;
  6458. dy = +dy || 0;
  6459. this.transform(this._.transform.concat([["t", dx, dy]]));
  6460. return this;
  6461. };
  6462. /*\
  6463. * Element.transform
  6464. [ method ]
  6465. **
  6466. * Adds transformation to the element which is separate to other attributes,
  6467. * i.e. translation doesn’t change `x` or `y` of the rectange. The format
  6468. * of transformation string is similar to the path string syntax:
  6469. | "t100,100r30,100,100s2,2,100,100r45s1.5"
  6470. * Each letter is a command. There are four commands: `t` is for translate, `r` is for rotate, `s` is for
  6471. * scale and `m` is for matrix.
  6472. *
  6473. * There are also alternative “absolute” translation, rotation and scale: `T`, `R` and `S`. They will not take previous transformation into account. For example, `...T100,0` will always move element 100 px horisontally, while `...t100,0` could move it vertically if there is `r90` before. Just compare results of `r90t100,0` and `r90T100,0`.
  6474. *
  6475. * So, the example line above could be read like “translate by 100, 100; rotate 30° around 100, 100; scale twice around 100, 100;
  6476. * rotate 45° around centre; scale 1.5 times relative to centre”. As you can see rotate and scale commands have origin
  6477. * coordinates as optional parameters, the default is the centre point of the element.
  6478. * Matrix accepts six parameters.
  6479. > Usage
  6480. | var el = paper.rect(10, 20, 300, 200);
  6481. | // translate 100, 100, rotate 45°, translate -100, 0
  6482. | el.transform("t100,100r45t-100,0");
  6483. | // if you want you can append or prepend transformations
  6484. | el.transform("...t50,50");
  6485. | el.transform("s2...");
  6486. | // or even wrap
  6487. | el.transform("t50,50...t-50-50");
  6488. | // to reset transformation call method with empty string
  6489. | el.transform("");
  6490. | // to get current value call it without parameters
  6491. | console.log(el.transform());
  6492. > Parameters
  6493. - tstr (string) #optional transformation string
  6494. * If tstr isn’t specified
  6495. = (string) current transformation string
  6496. * else
  6497. = (object) @Element
  6498. \*/
  6499. elproto.transform = function (tstr) {
  6500. var _ = this._;
  6501. if (tstr == null) {
  6502. return _.transform;
  6503. }
  6504. R._extractTransform(this, tstr);
  6505. this.clip && $(this.clip, {transform: this.matrix.invert()});
  6506. this.pattern && updatePosition(this);
  6507. this.node && $(this.node, {transform: this.matrix});
  6508. if (_.sx != 1 || _.sy != 1) {
  6509. var sw = this.attrs[has]("stroke-width") ? this.attrs["stroke-width"] : 1;
  6510. this.attr({"stroke-width": sw});
  6511. }
  6512. return this;
  6513. };
  6514. /*\
  6515. * Element.hide
  6516. [ method ]
  6517. **
  6518. * Makes element invisible. See @Element.show.
  6519. = (object) @Element
  6520. \*/
  6521. elproto.hide = function () {
  6522. !this.removed && this.paper.safari(this.node.style.display = "none");
  6523. return this;
  6524. };
  6525. /*\
  6526. * Element.show
  6527. [ method ]
  6528. **
  6529. * Makes element visible. See @Element.hide.
  6530. = (object) @Element
  6531. \*/
  6532. elproto.show = function () {
  6533. !this.removed && this.paper.safari(this.node.style.display = "");
  6534. return this;
  6535. };
  6536. /*\
  6537. * Element.remove
  6538. [ method ]
  6539. **
  6540. * Removes element from the paper.
  6541. \*/
  6542. elproto.remove = function () {
  6543. if (this.removed || !this.node.parentNode) {
  6544. return;
  6545. }
  6546. var paper = this.paper;
  6547. paper.__set__ && paper.__set__.exclude(this);
  6548. eve.unbind("raphael.*.*." + this.id);
  6549. if (this.gradient) {
  6550. paper.defs.removeChild(this.gradient);
  6551. }
  6552. R._tear(this, paper);
  6553. if (this.node.parentNode.tagName.toLowerCase() == "a") {
  6554. this.node.parentNode.parentNode.removeChild(this.node.parentNode);
  6555. } else {
  6556. this.node.parentNode.removeChild(this.node);
  6557. }
  6558. for (var i in this) {
  6559. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  6560. }
  6561. this.removed = true;
  6562. };
  6563. elproto._getBBox = function () {
  6564. if (this.node.style.display == "none") {
  6565. this.show();
  6566. var hide = true;
  6567. }
  6568. var bbox = {};
  6569. try {
  6570. bbox = this.node.getBBox();
  6571. } catch(e) {
  6572. // Firefox 3.0.x plays badly here
  6573. } finally {
  6574. bbox = bbox || {};
  6575. }
  6576. hide && this.hide();
  6577. return bbox;
  6578. };
  6579. /*\
  6580. * Element.attr
  6581. [ method ]
  6582. **
  6583. * Sets the attributes of the element.
  6584. > Parameters
  6585. - attrName (string) attribute’s name
  6586. - value (string) value
  6587. * or
  6588. - params (object) object of name/value pairs
  6589. * or
  6590. - attrName (string) attribute’s name
  6591. * or
  6592. - attrNames (array) in this case method returns array of current values for given attribute names
  6593. = (object) @Element if attrsName & value or params are passed in.
  6594. = (...) value of the attribute if only attrsName is passed in.
  6595. = (array) array of values of the attribute if attrsNames is passed in.
  6596. = (object) object of attributes if nothing is passed in.
  6597. > Possible parameters
  6598. # <p>Please refer to the <a href="http://www.w3.org/TR/SVG/" title="The W3C Recommendation for the SVG language describes these properties in detail.">SVG specification</a> for an explanation of these parameters.</p>
  6599. o arrow-end (string) arrowhead on the end of the path. The format for string is `<type>[-<width>[-<length>]]`. Possible types: `classic`, `block`, `open`, `oval`, `diamond`, `none`, width: `wide`, `narrow`, `medium`, length: `long`, `short`, `midium`.
  6600. o clip-rect (string) comma or space separated values: x, y, width and height
  6601. o cursor (string) CSS type of the cursor
  6602. o cx (number) the x-axis coordinate of the center of the circle, or ellipse
  6603. o cy (number) the y-axis coordinate of the center of the circle, or ellipse
  6604. o fill (string) colour, gradient or image
  6605. o fill-opacity (number)
  6606. o font (string)
  6607. o font-family (string)
  6608. o font-size (number) font size in pixels
  6609. o font-weight (string)
  6610. o height (number)
  6611. o href (string) URL, if specified element behaves as hyperlink
  6612. o opacity (number)
  6613. o path (string) SVG path string format
  6614. o r (number) radius of the circle, ellipse or rounded corner on the rect
  6615. o rx (number) horisontal radius of the ellipse
  6616. o ry (number) vertical radius of the ellipse
  6617. o src (string) image URL, only works for @Element.image element
  6618. o stroke (string) stroke colour
  6619. o stroke-dasharray (string) [“”, “`-`”, “`.`”, “`-.`”, “`-..`”, “`. `”, “`- `”, “`--`”, “`- .`”, “`--.`”, “`--..`”]
  6620. o stroke-linecap (string) [“`butt`”, “`square`”, “`round`”]
  6621. o stroke-linejoin (string) [“`bevel`”, “`round`”, “`miter`”]
  6622. o stroke-miterlimit (number)
  6623. o stroke-opacity (number)
  6624. o stroke-width (number) stroke width in pixels, default is '1'
  6625. o target (string) used with href
  6626. o text (string) contents of the text element. Use `\n` for multiline text
  6627. o text-anchor (string) [“`start`”, “`middle`”, “`end`”], default is “`middle`”
  6628. o title (string) will create tooltip with a given text
  6629. o transform (string) see @Element.transform
  6630. o width (number)
  6631. o x (number)
  6632. o y (number)
  6633. > Gradients
  6634. * Linear gradient format: “`‹angle›-‹colour›[-‹colour›[:‹offset›]]*-‹colour›`”, example: “`90-#fff-#000`” – 90°
  6635. * gradient from white to black or “`0-#fff-#f00:20-#000`” – 0° gradient from white via red (at 20%) to black.
  6636. *
  6637. * radial gradient: “`r[(‹fx›, ‹fy›)]‹colour›[-‹colour›[:‹offset›]]*-‹colour›`”, example: “`r#fff-#000`” –
  6638. * gradient from white to black or “`r(0.25, 0.75)#fff-#000`” – gradient from white to black with focus point
  6639. * at 0.25, 0.75. Focus point coordinates are in 0..1 range. Radial gradients can only be applied to circles and ellipses.
  6640. > Path String
  6641. # <p>Please refer to <a href="http://www.w3.org/TR/SVG/paths.html#PathData" title="Details of a path’s data attribute’s format are described in the SVG specification.">SVG documentation regarding path string</a>. Raphaël fully supports it.</p>
  6642. > Colour Parsing
  6643. # <ul>
  6644. # <li>Colour name (“<code>red</code>”, “<code>green</code>”, “<code>cornflowerblue</code>”, etc)</li>
  6645. # <li>#••• — shortened HTML colour: (“<code>#000</code>”, “<code>#fc0</code>”, etc)</li>
  6646. # <li>#•••••• — full length HTML colour: (“<code>#000000</code>”, “<code>#bd2300</code>”)</li>
  6647. # <li>rgb(•••, •••, •••) — red, green and blue channels’ values: (“<code>rgb(200,&nbsp;100,&nbsp;0)</code>”)</li>
  6648. # <li>rgb(•••%, •••%, •••%) — same as above, but in %: (“<code>rgb(100%,&nbsp;175%,&nbsp;0%)</code>”)</li>
  6649. # <li>rgba(•••, •••, •••, •••) — red, green and blue channels’ values: (“<code>rgba(200,&nbsp;100,&nbsp;0, .5)</code>”)</li>
  6650. # <li>rgba(•••%, •••%, •••%, •••%) — same as above, but in %: (“<code>rgba(100%,&nbsp;175%,&nbsp;0%, 50%)</code>”)</li>
  6651. # <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (“<code>hsb(0.5,&nbsp;0.25,&nbsp;1)</code>”)</li>
  6652. # <li>hsb(•••%, •••%, •••%) — same as above, but in %</li>
  6653. # <li>hsba(•••, •••, •••, •••) — same as above, but with opacity</li>
  6654. # <li>hsl(•••, •••, •••) — almost the same as hsb, see <a href="http://en.wikipedia.org/wiki/HSL_and_HSV" title="HSL and HSV - Wikipedia, the free encyclopedia">Wikipedia page</a></li>
  6655. # <li>hsl(•••%, •••%, •••%) — same as above, but in %</li>
  6656. # <li>hsla(•••, •••, •••, •••) — same as above, but with opacity</li>
  6657. # <li>Optionally for hsb and hsl you could specify hue as a degree: “<code>hsl(240deg,&nbsp;1,&nbsp;.5)</code>” or, if you want to go fancy, “<code>hsl(240°,&nbsp;1,&nbsp;.5)</code>”</li>
  6658. # </ul>
  6659. \*/
  6660. elproto.attr = function (name, value) {
  6661. if (this.removed) {
  6662. return this;
  6663. }
  6664. if (name == null) {
  6665. var res = {};
  6666. for (var a in this.attrs) if (this.attrs[has](a)) {
  6667. res[a] = this.attrs[a];
  6668. }
  6669. res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
  6670. res.transform = this._.transform;
  6671. return res;
  6672. }
  6673. if (value == null && R.is(name, "string")) {
  6674. if (name == "fill" && this.attrs.fill == "none" && this.attrs.gradient) {
  6675. return this.attrs.gradient;
  6676. }
  6677. if (name == "transform") {
  6678. return this._.transform;
  6679. }
  6680. var names = name.split(separator),
  6681. out = {};
  6682. for (var i = 0, ii = names.length; i < ii; i++) {
  6683. name = names[i];
  6684. if (name in this.attrs) {
  6685. out[name] = this.attrs[name];
  6686. } else if (R.is(this.paper.customAttributes[name], "function")) {
  6687. out[name] = this.paper.customAttributes[name].def;
  6688. } else {
  6689. out[name] = R._availableAttrs[name];
  6690. }
  6691. }
  6692. return ii - 1 ? out : out[names[0]];
  6693. }
  6694. if (value == null && R.is(name, "array")) {
  6695. out = {};
  6696. for (i = 0, ii = name.length; i < ii; i++) {
  6697. out[name[i]] = this.attr(name[i]);
  6698. }
  6699. return out;
  6700. }
  6701. if (value != null) {
  6702. var params = {};
  6703. params[name] = value;
  6704. } else if (name != null && R.is(name, "object")) {
  6705. params = name;
  6706. }
  6707. for (var key in params) {
  6708. eve("raphael.attr." + key + "." + this.id, this, params[key]);
  6709. }
  6710. for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
  6711. var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
  6712. this.attrs[key] = params[key];
  6713. for (var subkey in par) if (par[has](subkey)) {
  6714. params[subkey] = par[subkey];
  6715. }
  6716. }
  6717. setFillAndStroke(this, params);
  6718. return this;
  6719. };
  6720. /*\
  6721. * Element.toFront
  6722. [ method ]
  6723. **
  6724. * Moves the element so it is the closest to the viewer’s eyes, on top of other elements.
  6725. = (object) @Element
  6726. \*/
  6727. elproto.toFront = function () {
  6728. if (this.removed) {
  6729. return this;
  6730. }
  6731. if (this.node.parentNode.tagName.toLowerCase() == "a") {
  6732. this.node.parentNode.parentNode.appendChild(this.node.parentNode);
  6733. } else {
  6734. this.node.parentNode.appendChild(this.node);
  6735. }
  6736. var svg = this.paper;
  6737. svg.top != this && R._tofront(this, svg);
  6738. return this;
  6739. };
  6740. /*\
  6741. * Element.toBack
  6742. [ method ]
  6743. **
  6744. * Moves the element so it is the furthest from the viewer’s eyes, behind other elements.
  6745. = (object) @Element
  6746. \*/
  6747. elproto.toBack = function () {
  6748. if (this.removed) {
  6749. return this;
  6750. }
  6751. var parent = this.node.parentNode;
  6752. if (parent.tagName.toLowerCase() == "a") {
  6753. parent.parentNode.insertBefore(this.node.parentNode, this.node.parentNode.parentNode.firstChild);
  6754. } else if (parent.firstChild != this.node) {
  6755. parent.insertBefore(this.node, this.node.parentNode.firstChild);
  6756. }
  6757. R._toback(this, this.paper);
  6758. var svg = this.paper;
  6759. return this;
  6760. };
  6761. /*\
  6762. * Element.insertAfter
  6763. [ method ]
  6764. **
  6765. * Inserts current object after the given one.
  6766. = (object) @Element
  6767. \*/
  6768. elproto.insertAfter = function (element) {
  6769. if (this.removed) {
  6770. return this;
  6771. }
  6772. var node = element.node || element[element.length - 1].node;
  6773. if (node.nextSibling) {
  6774. node.parentNode.insertBefore(this.node, node.nextSibling);
  6775. } else {
  6776. node.parentNode.appendChild(this.node);
  6777. }
  6778. R._insertafter(this, element, this.paper);
  6779. return this;
  6780. };
  6781. /*\
  6782. * Element.insertBefore
  6783. [ method ]
  6784. **
  6785. * Inserts current object before the given one.
  6786. = (object) @Element
  6787. \*/
  6788. elproto.insertBefore = function (element) {
  6789. if (this.removed) {
  6790. return this;
  6791. }
  6792. var node = element.node || element[0].node;
  6793. node.parentNode.insertBefore(this.node, node);
  6794. R._insertbefore(this, element, this.paper);
  6795. return this;
  6796. };
  6797. elproto.blur = function (size) {
  6798. // Experimental. No Safari support. Use it on your own risk.
  6799. var t = this;
  6800. if (+size !== 0) {
  6801. var fltr = $("filter"),
  6802. blur = $("feGaussianBlur");
  6803. t.attrs.blur = size;
  6804. fltr.id = R.createUUID();
  6805. $(blur, {stdDeviation: +size || 1.5});
  6806. fltr.appendChild(blur);
  6807. t.paper.defs.appendChild(fltr);
  6808. t._blur = fltr;
  6809. $(t.node, {filter: "url(#" + fltr.id + ")"});
  6810. } else {
  6811. if (t._blur) {
  6812. t._blur.parentNode.removeChild(t._blur);
  6813. delete t._blur;
  6814. delete t.attrs.blur;
  6815. }
  6816. t.node.removeAttribute("filter");
  6817. }
  6818. return t;
  6819. };
  6820. R._engine.circle = function (svg, x, y, r) {
  6821. var el = $("circle");
  6822. svg.canvas && svg.canvas.appendChild(el);
  6823. var res = new Element(el, svg);
  6824. res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
  6825. res.type = "circle";
  6826. $(el, res.attrs);
  6827. return res;
  6828. };
  6829. R._engine.rect = function (svg, x, y, w, h, r) {
  6830. var el = $("rect");
  6831. svg.canvas && svg.canvas.appendChild(el);
  6832. var res = new Element(el, svg);
  6833. res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
  6834. res.type = "rect";
  6835. $(el, res.attrs);
  6836. return res;
  6837. };
  6838. R._engine.ellipse = function (svg, x, y, rx, ry) {
  6839. var el = $("ellipse");
  6840. svg.canvas && svg.canvas.appendChild(el);
  6841. var res = new Element(el, svg);
  6842. res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
  6843. res.type = "ellipse";
  6844. $(el, res.attrs);
  6845. return res;
  6846. };
  6847. R._engine.image = function (svg, src, x, y, w, h) {
  6848. var el = $("image");
  6849. $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
  6850. el.setAttributeNS(xlink, "href", src);
  6851. svg.canvas && svg.canvas.appendChild(el);
  6852. var res = new Element(el, svg);
  6853. res.attrs = {x: x, y: y, width: w, height: h, src: src};
  6854. res.type = "image";
  6855. return res;
  6856. };
  6857. R._engine.text = function (svg, x, y, text) {
  6858. var el = $("text");
  6859. svg.canvas && svg.canvas.appendChild(el);
  6860. var res = new Element(el, svg);
  6861. res.attrs = {
  6862. x: x,
  6863. y: y,
  6864. "text-anchor": "middle",
  6865. text: text,
  6866. font: R._availableAttrs.font,
  6867. stroke: "none",
  6868. fill: "#000"
  6869. };
  6870. res.type = "text";
  6871. setFillAndStroke(res, res.attrs);
  6872. return res;
  6873. };
  6874. R._engine.setSize = function (width, height) {
  6875. this.width = width || this.width;
  6876. this.height = height || this.height;
  6877. this.canvas.setAttribute("width", this.width);
  6878. this.canvas.setAttribute("height", this.height);
  6879. if (this._viewBox) {
  6880. this.setViewBox.apply(this, this._viewBox);
  6881. }
  6882. return this;
  6883. };
  6884. R._engine.create = function () {
  6885. var con = R._getContainer.apply(0, arguments),
  6886. container = con && con.container,
  6887. x = con.x,
  6888. y = con.y,
  6889. width = con.width,
  6890. height = con.height;
  6891. if (!container) {
  6892. throw new Error("SVG container not found.");
  6893. }
  6894. var cnvs = $("svg"),
  6895. css = "overflow:hidden;",
  6896. isFloating;
  6897. x = x || 0;
  6898. y = y || 0;
  6899. width = width || 512;
  6900. height = height || 342;
  6901. $(cnvs, {
  6902. height: height,
  6903. version: 1.1,
  6904. width: width,
  6905. xmlns: "http://www.w3.org/2000/svg"
  6906. });
  6907. if (container == 1) {
  6908. cnvs.style.cssText = css + "position:absolute;left:" + x + "px;top:" + y + "px";
  6909. R._g.doc.body.appendChild(cnvs);
  6910. isFloating = 1;
  6911. } else {
  6912. cnvs.style.cssText = css + "position:relative";
  6913. if (container.firstChild) {
  6914. container.insertBefore(cnvs, container.firstChild);
  6915. } else {
  6916. container.appendChild(cnvs);
  6917. }
  6918. }
  6919. container = new R._Paper;
  6920. container.width = width;
  6921. container.height = height;
  6922. container.canvas = cnvs;
  6923. container.clear();
  6924. container._left = container._top = 0;
  6925. isFloating && (container.renderfix = function () {});
  6926. container.renderfix();
  6927. return container;
  6928. };
  6929. R._engine.setViewBox = function (x, y, w, h, fit) {
  6930. eve("raphael.setViewBox", this, this._viewBox, [x, y, w, h, fit]);
  6931. var size = mmax(w / this.width, h / this.height),
  6932. top = this.top,
  6933. aspectRatio = fit ? "meet" : "xMinYMin",
  6934. vb,
  6935. sw;
  6936. if (x == null) {
  6937. if (this._vbSize) {
  6938. size = 1;
  6939. }
  6940. delete this._vbSize;
  6941. vb = "0 0 " + this.width + S + this.height;
  6942. } else {
  6943. this._vbSize = size;
  6944. vb = x + S + y + S + w + S + h;
  6945. }
  6946. $(this.canvas, {
  6947. viewBox: vb,
  6948. preserveAspectRatio: aspectRatio
  6949. });
  6950. while (size && top) {
  6951. sw = "stroke-width" in top.attrs ? top.attrs["stroke-width"] : 1;
  6952. top.attr({"stroke-width": sw});
  6953. top._.dirty = 1;
  6954. top._.dirtyT = 1;
  6955. top = top.prev;
  6956. }
  6957. this._viewBox = [x, y, w, h, !!fit];
  6958. return this;
  6959. };
  6960. /*\
  6961. * Paper.renderfix
  6962. [ method ]
  6963. **
  6964. * Fixes the issue of Firefox and IE9 regarding subpixel rendering. If paper is dependant
  6965. * on other elements after reflow it could shift half pixel which cause for lines to lost their crispness.
  6966. * This method fixes the issue.
  6967. **
  6968. Special thanks to Mariusz Nowak (http://www.medikoo.com/) for this method.
  6969. \*/
  6970. R.prototype.renderfix = function () {
  6971. var cnvs = this.canvas,
  6972. s = cnvs.style,
  6973. pos;
  6974. try {
  6975. pos = cnvs.getScreenCTM() || cnvs.createSVGMatrix();
  6976. } catch (e) {
  6977. pos = cnvs.createSVGMatrix();
  6978. }
  6979. var left = -pos.e % 1,
  6980. top = -pos.f % 1;
  6981. if (left || top) {
  6982. if (left) {
  6983. this._left = (this._left + left) % 1;
  6984. s.left = this._left + "px";
  6985. }
  6986. if (top) {
  6987. this._top = (this._top + top) % 1;
  6988. s.top = this._top + "px";
  6989. }
  6990. }
  6991. };
  6992. /*\
  6993. * Paper.clear
  6994. [ method ]
  6995. **
  6996. * Clears the paper, i.e. removes all the elements.
  6997. \*/
  6998. R.prototype.clear = function () {
  6999. R.eve("raphael.clear", this);
  7000. var c = this.canvas;
  7001. while (c.firstChild) {
  7002. c.removeChild(c.firstChild);
  7003. }
  7004. this.bottom = this.top = null;
  7005. (this.desc = $("desc")).appendChild(R._g.doc.createTextNode("Created with Rapha\xebl " + R.version));
  7006. c.appendChild(this.desc);
  7007. c.appendChild(this.defs = $("defs"));
  7008. };
  7009. /*\
  7010. * Paper.remove
  7011. [ method ]
  7012. **
  7013. * Removes the paper from the DOM.
  7014. \*/
  7015. R.prototype.remove = function () {
  7016. eve("raphael.remove", this);
  7017. this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
  7018. for (var i in this) {
  7019. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  7020. }
  7021. };
  7022. var setproto = R.st;
  7023. for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
  7024. setproto[method] = (function (methodname) {
  7025. return function () {
  7026. var arg = arguments;
  7027. return this.forEach(function (el) {
  7028. el[methodname].apply(el, arg);
  7029. });
  7030. };
  7031. })(method);
  7032. }
  7033. })();
  7034. // ┌─────────────────────────────────────────────────────────────────────┐ \\
  7035. // │ Raphaël - JavaScript Vector Library │ \\
  7036. // ├─────────────────────────────────────────────────────────────────────┤ \\
  7037. // │ VML Module │ \\
  7038. // ├─────────────────────────────────────────────────────────────────────┤ \\
  7039. // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
  7040. // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
  7041. // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
  7042. // └─────────────────────────────────────────────────────────────────────┘ \\
  7043. (function(){
  7044. if (!R.vml) {
  7045. return;
  7046. }
  7047. var has = "hasOwnProperty",
  7048. Str = String,
  7049. toFloat = parseFloat,
  7050. math = Math,
  7051. round = math.round,
  7052. mmax = math.max,
  7053. mmin = math.min,
  7054. abs = math.abs,
  7055. fillString = "fill",
  7056. separator = /[, ]+/,
  7057. eve = R.eve,
  7058. ms = " progid:DXImageTransform.Microsoft",
  7059. S = " ",
  7060. E = "",
  7061. map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
  7062. bites = /([clmz]),?([^clmz]*)/gi,
  7063. blurregexp = / progid:\S+Blur\([^\)]+\)/g,
  7064. val = /-?[^,\s-]+/g,
  7065. cssDot = "position:absolute;left:0;top:0;width:1px;height:1px",
  7066. zoom = 21600,
  7067. pathTypes = {path: 1, rect: 1, image: 1},
  7068. ovalTypes = {circle: 1, ellipse: 1},
  7069. path2vml = function (path) {
  7070. var total = /[ahqstv]/ig,
  7071. command = R._pathToAbsolute;
  7072. Str(path).match(total) && (command = R._path2curve);
  7073. total = /[clmz]/g;
  7074. if (command == R._pathToAbsolute && !Str(path).match(total)) {
  7075. var res = Str(path).replace(bites, function (all, command, args) {
  7076. var vals = [],
  7077. isMove = command.toLowerCase() == "m",
  7078. res = map[command];
  7079. args.replace(val, function (value) {
  7080. if (isMove && vals.length == 2) {
  7081. res += vals + map[command == "m" ? "l" : "L"];
  7082. vals = [];
  7083. }
  7084. vals.push(round(value * zoom));
  7085. });
  7086. return res + vals;
  7087. });
  7088. return res;
  7089. }
  7090. var pa = command(path), p, r;
  7091. res = [];
  7092. for (var i = 0, ii = pa.length; i < ii; i++) {
  7093. p = pa[i];
  7094. r = pa[i][0].toLowerCase();
  7095. r == "z" && (r = "x");
  7096. for (var j = 1, jj = p.length; j < jj; j++) {
  7097. r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
  7098. }
  7099. res.push(r);
  7100. }
  7101. return res.join(S);
  7102. },
  7103. compensation = function (deg, dx, dy) {
  7104. var m = R.matrix();
  7105. m.rotate(-deg, .5, .5);
  7106. return {
  7107. dx: m.x(dx, dy),
  7108. dy: m.y(dx, dy)
  7109. };
  7110. },
  7111. setCoords = function (p, sx, sy, dx, dy, deg) {
  7112. var _ = p._,
  7113. m = p.matrix,
  7114. fillpos = _.fillpos,
  7115. o = p.node,
  7116. s = o.style,
  7117. y = 1,
  7118. flip = "",
  7119. dxdy,
  7120. kx = zoom / sx,
  7121. ky = zoom / sy;
  7122. s.visibility = "hidden";
  7123. if (!sx || !sy) {
  7124. return;
  7125. }
  7126. o.coordsize = abs(kx) + S + abs(ky);
  7127. s.rotation = deg * (sx * sy < 0 ? -1 : 1);
  7128. if (deg) {
  7129. var c = compensation(deg, dx, dy);
  7130. dx = c.dx;
  7131. dy = c.dy;
  7132. }
  7133. sx < 0 && (flip += "x");
  7134. sy < 0 && (flip += " y") && (y = -1);
  7135. s.flip = flip;
  7136. o.coordorigin = (dx * -kx) + S + (dy * -ky);
  7137. if (fillpos || _.fillsize) {
  7138. var fill = o.getElementsByTagName(fillString);
  7139. fill = fill && fill[0];
  7140. o.removeChild(fill);
  7141. if (fillpos) {
  7142. c = compensation(deg, m.x(fillpos[0], fillpos[1]), m.y(fillpos[0], fillpos[1]));
  7143. fill.position = c.dx * y + S + c.dy * y;
  7144. }
  7145. if (_.fillsize) {
  7146. fill.size = _.fillsize[0] * abs(sx) + S + _.fillsize[1] * abs(sy);
  7147. }
  7148. o.appendChild(fill);
  7149. }
  7150. s.visibility = "visible";
  7151. };
  7152. R.toString = function () {
  7153. return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
  7154. };
  7155. var addArrow = function (o, value, isEnd) {
  7156. var values = Str(value).toLowerCase().split("-"),
  7157. se = isEnd ? "end" : "start",
  7158. i = values.length,
  7159. type = "classic",
  7160. w = "medium",
  7161. h = "medium";
  7162. while (i--) {
  7163. switch (values[i]) {
  7164. case "block":
  7165. case "classic":
  7166. case "oval":
  7167. case "diamond":
  7168. case "open":
  7169. case "none":
  7170. type = values[i];
  7171. break;
  7172. case "wide":
  7173. case "narrow": h = values[i]; break;
  7174. case "long":
  7175. case "short": w = values[i]; break;
  7176. }
  7177. }
  7178. var stroke = o.node.getElementsByTagName("stroke")[0];
  7179. stroke[se + "arrow"] = type;
  7180. stroke[se + "arrowlength"] = w;
  7181. stroke[se + "arrowwidth"] = h;
  7182. },
  7183. setFillAndStroke = function (o, params) {
  7184. // o.paper.canvas.style.display = "none";
  7185. o.attrs = o.attrs || {};
  7186. var node = o.node,
  7187. a = o.attrs,
  7188. s = node.style,
  7189. xy,
  7190. 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),
  7191. isOval = ovalTypes[o.type] && (a.cx != params.cx || a.cy != params.cy || a.r != params.r || a.rx != params.rx || a.ry != params.ry),
  7192. res = o;
  7193. for (var par in params) if (params[has](par)) {
  7194. a[par] = params[par];
  7195. }
  7196. if (newpath) {
  7197. a.path = R._getPath[o.type](o);
  7198. o._.dirty = 1;
  7199. }
  7200. params.href && (node.href = params.href);
  7201. params.title && (node.title = params.title);
  7202. params.target && (node.target = params.target);
  7203. params.cursor && (s.cursor = params.cursor);
  7204. "blur" in params && o.blur(params.blur);
  7205. if (params.path && o.type == "path" || newpath) {
  7206. node.path = path2vml(~Str(a.path).toLowerCase().indexOf("r") ? R._pathToAbsolute(a.path) : a.path);
  7207. if (o.type == "image") {
  7208. o._.fillpos = [a.x, a.y];
  7209. o._.fillsize = [a.width, a.height];
  7210. setCoords(o, 1, 1, 0, 0, 0);
  7211. }
  7212. }
  7213. "transform" in params && o.transform(params.transform);
  7214. if (isOval) {
  7215. var cx = +a.cx,
  7216. cy = +a.cy,
  7217. rx = +a.rx || +a.r || 0,
  7218. ry = +a.ry || +a.r || 0;
  7219. 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));
  7220. o._.dirty = 1;
  7221. }
  7222. if ("clip-rect" in params) {
  7223. var rect = Str(params["clip-rect"]).split(separator);
  7224. if (rect.length == 4) {
  7225. rect[2] = +rect[2] + (+rect[0]);
  7226. rect[3] = +rect[3] + (+rect[1]);
  7227. var div = node.clipRect || R._g.doc.createElement("div"),
  7228. dstyle = div.style;
  7229. dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
  7230. if (!node.clipRect) {
  7231. dstyle.position = "absolute";
  7232. dstyle.top = 0;
  7233. dstyle.left = 0;
  7234. dstyle.width = o.paper.width + "px";
  7235. dstyle.height = o.paper.height + "px";
  7236. node.parentNode.insertBefore(div, node);
  7237. div.appendChild(node);
  7238. node.clipRect = div;
  7239. }
  7240. }
  7241. if (!params["clip-rect"]) {
  7242. node.clipRect && (node.clipRect.style.clip = "auto");
  7243. }
  7244. }
  7245. if (o.textpath) {
  7246. var textpathStyle = o.textpath.style;
  7247. params.font && (textpathStyle.font = params.font);
  7248. params["font-family"] && (textpathStyle.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, E) + '"');
  7249. params["font-size"] && (textpathStyle.fontSize = params["font-size"]);
  7250. params["font-weight"] && (textpathStyle.fontWeight = params["font-weight"]);
  7251. params["font-style"] && (textpathStyle.fontStyle = params["font-style"]);
  7252. }
  7253. if ("arrow-start" in params) {
  7254. addArrow(res, params["arrow-start"]);
  7255. }
  7256. if ("arrow-end" in params) {
  7257. addArrow(res, params["arrow-end"], 1);
  7258. }
  7259. if (params.opacity != null ||
  7260. params["stroke-width"] != null ||
  7261. params.fill != null ||
  7262. params.src != null ||
  7263. params.stroke != null ||
  7264. params["stroke-width"] != null ||
  7265. params["stroke-opacity"] != null ||
  7266. params["fill-opacity"] != null ||
  7267. params["stroke-dasharray"] != null ||
  7268. params["stroke-miterlimit"] != null ||
  7269. params["stroke-linejoin"] != null ||
  7270. params["stroke-linecap"] != null) {
  7271. var fill = node.getElementsByTagName(fillString),
  7272. newfill = false;
  7273. fill = fill && fill[0];
  7274. !fill && (newfill = fill = createNode(fillString));
  7275. if (o.type == "image" && params.src) {
  7276. fill.src = params.src;
  7277. }
  7278. params.fill && (fill.on = true);
  7279. if (fill.on == null || params.fill == "none" || params.fill === null) {
  7280. fill.on = false;
  7281. }
  7282. if (fill.on && params.fill) {
  7283. var isURL = Str(params.fill).match(R._ISURL);
  7284. if (isURL) {
  7285. fill.parentNode == node && node.removeChild(fill);
  7286. fill.rotate = true;
  7287. fill.src = isURL[1];
  7288. fill.type = "tile";
  7289. var bbox = o.getBBox(1);
  7290. fill.position = bbox.x + S + bbox.y;
  7291. o._.fillpos = [bbox.x, bbox.y];
  7292. R._preload(isURL[1], function () {
  7293. o._.fillsize = [this.offsetWidth, this.offsetHeight];
  7294. });
  7295. } else {
  7296. fill.color = R.getRGB(params.fill).hex;
  7297. fill.src = E;
  7298. fill.type = "solid";
  7299. if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill, fill)) {
  7300. a.fill = "none";
  7301. a.gradient = params.fill;
  7302. fill.rotate = false;
  7303. }
  7304. }
  7305. }
  7306. if ("fill-opacity" in params || "opacity" in params) {
  7307. var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
  7308. opacity = mmin(mmax(opacity, 0), 1);
  7309. fill.opacity = opacity;
  7310. if (fill.src) {
  7311. fill.color = "none";
  7312. }
  7313. }
  7314. node.appendChild(fill);
  7315. var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
  7316. newstroke = false;
  7317. !stroke && (newstroke = stroke = createNode("stroke"));
  7318. if ((params.stroke && params.stroke != "none") ||
  7319. params["stroke-width"] ||
  7320. params["stroke-opacity"] != null ||
  7321. params["stroke-dasharray"] ||
  7322. params["stroke-miterlimit"] ||
  7323. params["stroke-linejoin"] ||
  7324. params["stroke-linecap"]) {
  7325. stroke.on = true;
  7326. }
  7327. (params.stroke == "none" || params.stroke === null || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
  7328. var strokeColor = R.getRGB(params.stroke);
  7329. stroke.on && params.stroke && (stroke.color = strokeColor.hex);
  7330. opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
  7331. var width = (toFloat(params["stroke-width"]) || 1) * .75;
  7332. opacity = mmin(mmax(opacity, 0), 1);
  7333. params["stroke-width"] == null && (width = a["stroke-width"]);
  7334. params["stroke-width"] && (stroke.weight = width);
  7335. width && width < 1 && (opacity *= width) && (stroke.weight = 1);
  7336. stroke.opacity = opacity;
  7337. params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
  7338. stroke.miterlimit = params["stroke-miterlimit"] || 8;
  7339. params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
  7340. if (params["stroke-dasharray"]) {
  7341. var dasharray = {
  7342. "-": "shortdash",
  7343. ".": "shortdot",
  7344. "-.": "shortdashdot",
  7345. "-..": "shortdashdotdot",
  7346. ". ": "dot",
  7347. "- ": "dash",
  7348. "--": "longdash",
  7349. "- .": "dashdot",
  7350. "--.": "longdashdot",
  7351. "--..": "longdashdotdot"
  7352. };
  7353. stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
  7354. }
  7355. newstroke && node.appendChild(stroke);
  7356. }
  7357. if (res.type == "text") {
  7358. res.paper.canvas.style.display = E;
  7359. var span = res.paper.span,
  7360. m = 100,
  7361. fontSize = a.font && a.font.match(/\d+(?:\.\d*)?(?=px)/);
  7362. s = span.style;
  7363. a.font && (s.font = a.font);
  7364. a["font-family"] && (s.fontFamily = a["font-family"]);
  7365. a["font-weight"] && (s.fontWeight = a["font-weight"]);
  7366. a["font-style"] && (s.fontStyle = a["font-style"]);
  7367. fontSize = toFloat(a["font-size"] || fontSize && fontSize[0]) || 10;
  7368. s.fontSize = fontSize * m + "px";
  7369. res.textpath.string && (span.innerHTML = Str(res.textpath.string).replace(/</g, "&#60;").replace(/&/g, "&#38;").replace(/\n/g, "<br>"));
  7370. var brect = span.getBoundingClientRect();
  7371. res.W = a.w = (brect.right - brect.left) / m;
  7372. res.H = a.h = (brect.bottom - brect.top) / m;
  7373. // res.paper.canvas.style.display = "none";
  7374. res.X = a.x;
  7375. res.Y = a.y + res.H / 2;
  7376. ("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));
  7377. var dirtyattrs = ["x", "y", "text", "font", "font-family", "font-weight", "font-style", "font-size"];
  7378. for (var d = 0, dd = dirtyattrs.length; d < dd; d++) if (dirtyattrs[d] in params) {
  7379. res._.dirty = 1;
  7380. break;
  7381. }
  7382. // text-anchor emulation
  7383. switch (a["text-anchor"]) {
  7384. case "start":
  7385. res.textpath.style["v-text-align"] = "left";
  7386. res.bbx = res.W / 2;
  7387. break;
  7388. case "end":
  7389. res.textpath.style["v-text-align"] = "right";
  7390. res.bbx = -res.W / 2;
  7391. break;
  7392. default:
  7393. res.textpath.style["v-text-align"] = "center";
  7394. res.bbx = 0;
  7395. break;
  7396. }
  7397. res.textpath.style["v-text-kern"] = true;
  7398. }
  7399. // res.paper.canvas.style.display = E;
  7400. },
  7401. addGradientFill = function (o, gradient, fill) {
  7402. o.attrs = o.attrs || {};
  7403. var attrs = o.attrs,
  7404. pow = Math.pow,
  7405. opacity,
  7406. oindex,
  7407. type = "linear",
  7408. fxfy = ".5 .5";
  7409. o.attrs.gradient = gradient;
  7410. gradient = Str(gradient).replace(R._radial_gradient, function (all, fx, fy) {
  7411. type = "radial";
  7412. if (fx && fy) {
  7413. fx = toFloat(fx);
  7414. fy = toFloat(fy);
  7415. pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
  7416. fxfy = fx + S + fy;
  7417. }
  7418. return E;
  7419. });
  7420. gradient = gradient.split(/\s*\-\s*/);
  7421. if (type == "linear") {
  7422. var angle = gradient.shift();
  7423. angle = -toFloat(angle);
  7424. if (isNaN(angle)) {
  7425. return null;
  7426. }
  7427. }
  7428. var dots = R._parseDots(gradient);
  7429. if (!dots) {
  7430. return null;
  7431. }
  7432. o = o.shape || o.node;
  7433. if (dots.length) {
  7434. o.removeChild(fill);
  7435. fill.on = true;
  7436. fill.method = "none";
  7437. fill.color = dots[0].color;
  7438. fill.color2 = dots[dots.length - 1].color;
  7439. var clrs = [];
  7440. for (var i = 0, ii = dots.length; i < ii; i++) {
  7441. dots[i].offset && clrs.push(dots[i].offset + S + dots[i].color);
  7442. }
  7443. fill.colors = clrs.length ? clrs.join() : "0% " + fill.color;
  7444. if (type == "radial") {
  7445. fill.type = "gradientTitle";
  7446. fill.focus = "100%";
  7447. fill.focussize = "0 0";
  7448. fill.focusposition = fxfy;
  7449. fill.angle = 0;
  7450. } else {
  7451. // fill.rotate= true;
  7452. fill.type = "gradient";
  7453. fill.angle = (270 - angle) % 360;
  7454. }
  7455. o.appendChild(fill);
  7456. }
  7457. return 1;
  7458. },
  7459. Element = function (node, vml) {
  7460. this[0] = this.node = node;
  7461. node.raphael = true;
  7462. this.id = R._oid++;
  7463. node.raphaelid = this.id;
  7464. this.X = 0;
  7465. this.Y = 0;
  7466. this.attrs = {};
  7467. this.paper = vml;
  7468. this.matrix = R.matrix();
  7469. this._ = {
  7470. transform: [],
  7471. sx: 1,
  7472. sy: 1,
  7473. dx: 0,
  7474. dy: 0,
  7475. deg: 0,
  7476. dirty: 1,
  7477. dirtyT: 1
  7478. };
  7479. !vml.bottom && (vml.bottom = this);
  7480. this.prev = vml.top;
  7481. vml.top && (vml.top.next = this);
  7482. vml.top = this;
  7483. this.next = null;
  7484. };
  7485. var elproto = R.el;
  7486. Element.prototype = elproto;
  7487. elproto.constructor = Element;
  7488. elproto.transform = function (tstr) {
  7489. if (tstr == null) {
  7490. return this._.transform;
  7491. }
  7492. var vbs = this.paper._viewBoxShift,
  7493. vbt = vbs ? "s" + [vbs.scale, vbs.scale] + "-1-1t" + [vbs.dx, vbs.dy] : E,
  7494. oldt;
  7495. if (vbs) {
  7496. oldt = tstr = Str(tstr).replace(/\.{3}|\u2026/g, this._.transform || E);
  7497. }
  7498. R._extractTransform(this, vbt + tstr);
  7499. var matrix = this.matrix.clone(),
  7500. skew = this.skew,
  7501. o = this.node,
  7502. split,
  7503. isGrad = ~Str(this.attrs.fill).indexOf("-"),
  7504. isPatt = !Str(this.attrs.fill).indexOf("url(");
  7505. matrix.translate(1, 1);
  7506. if (isPatt || isGrad || this.type == "image") {
  7507. skew.matrix = "1 0 0 1";
  7508. skew.offset = "0 0";
  7509. split = matrix.split();
  7510. if ((isGrad && split.noRotation) || !split.isSimple) {
  7511. o.style.filter = matrix.toFilter();
  7512. var bb = this.getBBox(),
  7513. bbt = this.getBBox(1),
  7514. dx = bb.x - bbt.x,
  7515. dy = bb.y - bbt.y;
  7516. o.coordorigin = (dx * -zoom) + S + (dy * -zoom);
  7517. setCoords(this, 1, 1, dx, dy, 0);
  7518. } else {
  7519. o.style.filter = E;
  7520. setCoords(this, split.scalex, split.scaley, split.dx, split.dy, split.rotate);
  7521. }
  7522. } else {
  7523. o.style.filter = E;
  7524. skew.matrix = Str(matrix);
  7525. skew.offset = matrix.offset();
  7526. }
  7527. oldt && (this._.transform = oldt);
  7528. return this;
  7529. };
  7530. elproto.rotate = function (deg, cx, cy) {
  7531. if (this.removed) {
  7532. return this;
  7533. }
  7534. if (deg == null) {
  7535. return;
  7536. }
  7537. deg = Str(deg).split(separator);
  7538. if (deg.length - 1) {
  7539. cx = toFloat(deg[1]);
  7540. cy = toFloat(deg[2]);
  7541. }
  7542. deg = toFloat(deg[0]);
  7543. (cy == null) && (cx = cy);
  7544. if (cx == null || cy == null) {
  7545. var bbox = this.getBBox(1);
  7546. cx = bbox.x + bbox.width / 2;
  7547. cy = bbox.y + bbox.height / 2;
  7548. }
  7549. this._.dirtyT = 1;
  7550. this.transform(this._.transform.concat([["r", deg, cx, cy]]));
  7551. return this;
  7552. };
  7553. elproto.translate = function (dx, dy) {
  7554. if (this.removed) {
  7555. return this;
  7556. }
  7557. dx = Str(dx).split(separator);
  7558. if (dx.length - 1) {
  7559. dy = toFloat(dx[1]);
  7560. }
  7561. dx = toFloat(dx[0]) || 0;
  7562. dy = +dy || 0;
  7563. if (this._.bbox) {
  7564. this._.bbox.x += dx;
  7565. this._.bbox.y += dy;
  7566. }
  7567. this.transform(this._.transform.concat([["t", dx, dy]]));
  7568. return this;
  7569. };
  7570. elproto.scale = function (sx, sy, cx, cy) {
  7571. if (this.removed) {
  7572. return this;
  7573. }
  7574. sx = Str(sx).split(separator);
  7575. if (sx.length - 1) {
  7576. sy = toFloat(sx[1]);
  7577. cx = toFloat(sx[2]);
  7578. cy = toFloat(sx[3]);
  7579. isNaN(cx) && (cx = null);
  7580. isNaN(cy) && (cy = null);
  7581. }
  7582. sx = toFloat(sx[0]);
  7583. (sy == null) && (sy = sx);
  7584. (cy == null) && (cx = cy);
  7585. if (cx == null || cy == null) {
  7586. var bbox = this.getBBox(1);
  7587. }
  7588. cx = cx == null ? bbox.x + bbox.width / 2 : cx;
  7589. cy = cy == null ? bbox.y + bbox.height / 2 : cy;
  7590. this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
  7591. this._.dirtyT = 1;
  7592. return this;
  7593. };
  7594. elproto.hide = function () {
  7595. !this.removed && (this.node.style.display = "none");
  7596. return this;
  7597. };
  7598. elproto.show = function () {
  7599. !this.removed && (this.node.style.display = E);
  7600. return this;
  7601. };
  7602. elproto._getBBox = function () {
  7603. if (this.removed) {
  7604. return {};
  7605. }
  7606. return {
  7607. x: this.X + (this.bbx || 0) - this.W / 2,
  7608. y: this.Y - this.H,
  7609. width: this.W,
  7610. height: this.H
  7611. };
  7612. };
  7613. elproto.remove = function () {
  7614. if (this.removed || !this.node.parentNode) {
  7615. return;
  7616. }
  7617. this.paper.__set__ && this.paper.__set__.exclude(this);
  7618. R.eve.unbind("raphael.*.*." + this.id);
  7619. R._tear(this, this.paper);
  7620. this.node.parentNode.removeChild(this.node);
  7621. this.shape && this.shape.parentNode.removeChild(this.shape);
  7622. for (var i in this) {
  7623. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  7624. }
  7625. this.removed = true;
  7626. };
  7627. elproto.attr = function (name, value) {
  7628. if (this.removed) {
  7629. return this;
  7630. }
  7631. if (name == null) {
  7632. var res = {};
  7633. for (var a in this.attrs) if (this.attrs[has](a)) {
  7634. res[a] = this.attrs[a];
  7635. }
  7636. res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
  7637. res.transform = this._.transform;
  7638. return res;
  7639. }
  7640. if (value == null && R.is(name, "string")) {
  7641. if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
  7642. return this.attrs.gradient;
  7643. }
  7644. var names = name.split(separator),
  7645. out = {};
  7646. for (var i = 0, ii = names.length; i < ii; i++) {
  7647. name = names[i];
  7648. if (name in this.attrs) {
  7649. out[name] = this.attrs[name];
  7650. } else if (R.is(this.paper.customAttributes[name], "function")) {
  7651. out[name] = this.paper.customAttributes[name].def;
  7652. } else {
  7653. out[name] = R._availableAttrs[name];
  7654. }
  7655. }
  7656. return ii - 1 ? out : out[names[0]];
  7657. }
  7658. if (this.attrs && value == null && R.is(name, "array")) {
  7659. out = {};
  7660. for (i = 0, ii = name.length; i < ii; i++) {
  7661. out[name[i]] = this.attr(name[i]);
  7662. }
  7663. return out;
  7664. }
  7665. var params;
  7666. if (value != null) {
  7667. params = {};
  7668. params[name] = value;
  7669. }
  7670. value == null && R.is(name, "object") && (params = name);
  7671. for (var key in params) {
  7672. eve("raphael.attr." + key + "." + this.id, this, params[key]);
  7673. }
  7674. if (params) {
  7675. for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
  7676. var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
  7677. this.attrs[key] = params[key];
  7678. for (var subkey in par) if (par[has](subkey)) {
  7679. params[subkey] = par[subkey];
  7680. }
  7681. }
  7682. // this.paper.canvas.style.display = "none";
  7683. if (params.text && this.type == "text") {
  7684. this.textpath.string = params.text;
  7685. }
  7686. setFillAndStroke(this, params);
  7687. // this.paper.canvas.style.display = E;
  7688. }
  7689. return this;
  7690. };
  7691. elproto.toFront = function () {
  7692. !this.removed && this.node.parentNode.appendChild(this.node);
  7693. this.paper && this.paper.top != this && R._tofront(this, this.paper);
  7694. return this;
  7695. };
  7696. elproto.toBack = function () {
  7697. if (this.removed) {
  7698. return this;
  7699. }
  7700. if (this.node.parentNode.firstChild != this.node) {
  7701. this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
  7702. R._toback(this, this.paper);
  7703. }
  7704. return this;
  7705. };
  7706. elproto.insertAfter = function (element) {
  7707. if (this.removed) {
  7708. return this;
  7709. }
  7710. if (element.constructor == R.st.constructor) {
  7711. element = element[element.length - 1];
  7712. }
  7713. if (element.node.nextSibling) {
  7714. element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
  7715. } else {
  7716. element.node.parentNode.appendChild(this.node);
  7717. }
  7718. R._insertafter(this, element, this.paper);
  7719. return this;
  7720. };
  7721. elproto.insertBefore = function (element) {
  7722. if (this.removed) {
  7723. return this;
  7724. }
  7725. if (element.constructor == R.st.constructor) {
  7726. element = element[0];
  7727. }
  7728. element.node.parentNode.insertBefore(this.node, element.node);
  7729. R._insertbefore(this, element, this.paper);
  7730. return this;
  7731. };
  7732. elproto.blur = function (size) {
  7733. var s = this.node.runtimeStyle,
  7734. f = s.filter;
  7735. f = f.replace(blurregexp, E);
  7736. if (+size !== 0) {
  7737. this.attrs.blur = size;
  7738. s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
  7739. s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
  7740. } else {
  7741. s.filter = f;
  7742. s.margin = 0;
  7743. delete this.attrs.blur;
  7744. }
  7745. return this;
  7746. };
  7747. R._engine.path = function (pathString, vml) {
  7748. var el = createNode("shape");
  7749. el.style.cssText = cssDot;
  7750. el.coordsize = zoom + S + zoom;
  7751. el.coordorigin = vml.coordorigin;
  7752. var p = new Element(el, vml),
  7753. attr = {fill: "none", stroke: "#000"};
  7754. pathString && (attr.path = pathString);
  7755. p.type = "path";
  7756. p.path = [];
  7757. p.Path = E;
  7758. setFillAndStroke(p, attr);
  7759. vml.canvas.appendChild(el);
  7760. var skew = createNode("skew");
  7761. skew.on = true;
  7762. el.appendChild(skew);
  7763. p.skew = skew;
  7764. p.transform(E);
  7765. return p;
  7766. };
  7767. R._engine.rect = function (vml, x, y, w, h, r) {
  7768. var path = R._rectPath(x, y, w, h, r),
  7769. res = vml.path(path),
  7770. a = res.attrs;
  7771. res.X = a.x = x;
  7772. res.Y = a.y = y;
  7773. res.W = a.width = w;
  7774. res.H = a.height = h;
  7775. a.r = r;
  7776. a.path = path;
  7777. res.type = "rect";
  7778. return res;
  7779. };
  7780. R._engine.ellipse = function (vml, x, y, rx, ry) {
  7781. var res = vml.path(),
  7782. a = res.attrs;
  7783. res.X = x - rx;
  7784. res.Y = y - ry;
  7785. res.W = rx * 2;
  7786. res.H = ry * 2;
  7787. res.type = "ellipse";
  7788. setFillAndStroke(res, {
  7789. cx: x,
  7790. cy: y,
  7791. rx: rx,
  7792. ry: ry
  7793. });
  7794. return res;
  7795. };
  7796. R._engine.circle = function (vml, x, y, r) {
  7797. var res = vml.path(),
  7798. a = res.attrs;
  7799. res.X = x - r;
  7800. res.Y = y - r;
  7801. res.W = res.H = r * 2;
  7802. res.type = "circle";
  7803. setFillAndStroke(res, {
  7804. cx: x,
  7805. cy: y,
  7806. r: r
  7807. });
  7808. return res;
  7809. };
  7810. R._engine.image = function (vml, src, x, y, w, h) {
  7811. var path = R._rectPath(x, y, w, h),
  7812. res = vml.path(path).attr({stroke: "none"}),
  7813. a = res.attrs,
  7814. node = res.node,
  7815. fill = node.getElementsByTagName(fillString)[0];
  7816. a.src = src;
  7817. res.X = a.x = x;
  7818. res.Y = a.y = y;
  7819. res.W = a.width = w;
  7820. res.H = a.height = h;
  7821. a.path = path;
  7822. res.type = "image";
  7823. fill.parentNode == node && node.removeChild(fill);
  7824. fill.rotate = true;
  7825. fill.src = src;
  7826. fill.type = "tile";
  7827. res._.fillpos = [x, y];
  7828. res._.fillsize = [w, h];
  7829. node.appendChild(fill);
  7830. setCoords(res, 1, 1, 0, 0, 0);
  7831. return res;
  7832. };
  7833. R._engine.text = function (vml, x, y, text) {
  7834. var el = createNode("shape"),
  7835. path = createNode("path"),
  7836. o = createNode("textpath");
  7837. x = x || 0;
  7838. y = y || 0;
  7839. text = text || "";
  7840. path.v = R.format("m{0},{1}l{2},{1}", round(x * zoom), round(y * zoom), round(x * zoom) + 1);
  7841. path.textpathok = true;
  7842. o.string = Str(text);
  7843. o.on = true;
  7844. el.style.cssText = cssDot;
  7845. el.coordsize = zoom + S + zoom;
  7846. el.coordorigin = "0 0";
  7847. var p = new Element(el, vml),
  7848. attr = {
  7849. fill: "#000",
  7850. stroke: "none",
  7851. font: R._availableAttrs.font,
  7852. text: text
  7853. };
  7854. p.shape = el;
  7855. p.path = path;
  7856. p.textpath = o;
  7857. p.type = "text";
  7858. p.attrs.text = Str(text);
  7859. p.attrs.x = x;
  7860. p.attrs.y = y;
  7861. p.attrs.w = 1;
  7862. p.attrs.h = 1;
  7863. setFillAndStroke(p, attr);
  7864. el.appendChild(o);
  7865. el.appendChild(path);
  7866. vml.canvas.appendChild(el);
  7867. var skew = createNode("skew");
  7868. skew.on = true;
  7869. el.appendChild(skew);
  7870. p.skew = skew;
  7871. p.transform(E);
  7872. return p;
  7873. };
  7874. R._engine.setSize = function (width, height) {
  7875. var cs = this.canvas.style;
  7876. this.width = width;
  7877. this.height = height;
  7878. width == +width && (width += "px");
  7879. height == +height && (height += "px");
  7880. cs.width = width;
  7881. cs.height = height;
  7882. cs.clip = "rect(0 " + width + " " + height + " 0)";
  7883. if (this._viewBox) {
  7884. R._engine.setViewBox.apply(this, this._viewBox);
  7885. }
  7886. return this;
  7887. };
  7888. R._engine.setViewBox = function (x, y, w, h, fit) {
  7889. R.eve("raphael.setViewBox", this, this._viewBox, [x, y, w, h, fit]);
  7890. var width = this.width,
  7891. height = this.height,
  7892. size = 1 / mmax(w / width, h / height),
  7893. H, W;
  7894. if (fit) {
  7895. H = height / h;
  7896. W = width / w;
  7897. if (w * H < width) {
  7898. x -= (width - w * H) / 2 / H;
  7899. }
  7900. if (h * W < height) {
  7901. y -= (height - h * W) / 2 / W;
  7902. }
  7903. }
  7904. this._viewBox = [x, y, w, h, !!fit];
  7905. this._viewBoxShift = {
  7906. dx: -x,
  7907. dy: -y,
  7908. scale: size
  7909. };
  7910. this.forEach(function (el) {
  7911. el.transform("...");
  7912. });
  7913. return this;
  7914. };
  7915. var createNode;
  7916. R._engine.initWin = function (win) {
  7917. var doc = win.document;
  7918. doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
  7919. try {
  7920. !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
  7921. createNode = function (tagName) {
  7922. return doc.createElement('<rvml:' + tagName + ' class="rvml">');
  7923. };
  7924. } catch (e) {
  7925. createNode = function (tagName) {
  7926. return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
  7927. };
  7928. }
  7929. };
  7930. R._engine.initWin(R._g.win);
  7931. R._engine.create = function () {
  7932. var con = R._getContainer.apply(0, arguments),
  7933. container = con.container,
  7934. height = con.height,
  7935. s,
  7936. width = con.width,
  7937. x = con.x,
  7938. y = con.y;
  7939. if (!container) {
  7940. throw new Error("VML container not found.");
  7941. }
  7942. var res = new R._Paper,
  7943. c = res.canvas = R._g.doc.createElement("div"),
  7944. cs = c.style;
  7945. x = x || 0;
  7946. y = y || 0;
  7947. width = width || 512;
  7948. height = height || 342;
  7949. res.width = width;
  7950. res.height = height;
  7951. width == +width && (width += "px");
  7952. height == +height && (height += "px");
  7953. res.coordsize = zoom * 1e3 + S + zoom * 1e3;
  7954. res.coordorigin = "0 0";
  7955. res.span = R._g.doc.createElement("span");
  7956. res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;";
  7957. c.appendChild(res.span);
  7958. 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);
  7959. if (container == 1) {
  7960. R._g.doc.body.appendChild(c);
  7961. cs.left = x + "px";
  7962. cs.top = y + "px";
  7963. cs.position = "absolute";
  7964. } else {
  7965. if (container.firstChild) {
  7966. container.insertBefore(c, container.firstChild);
  7967. } else {
  7968. container.appendChild(c);
  7969. }
  7970. }
  7971. res.renderfix = function () {};
  7972. return res;
  7973. };
  7974. R.prototype.clear = function () {
  7975. R.eve("raphael.clear", this);
  7976. this.canvas.innerHTML = E;
  7977. this.span = R._g.doc.createElement("span");
  7978. this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
  7979. this.canvas.appendChild(this.span);
  7980. this.bottom = this.top = null;
  7981. };
  7982. R.prototype.remove = function () {
  7983. R.eve("raphael.remove", this);
  7984. this.canvas.parentNode.removeChild(this.canvas);
  7985. for (var i in this) {
  7986. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  7987. }
  7988. return true;
  7989. };
  7990. var setproto = R.st;
  7991. for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
  7992. setproto[method] = (function (methodname) {
  7993. return function () {
  7994. var arg = arguments;
  7995. return this.forEach(function (el) {
  7996. el[methodname].apply(el, arg);
  7997. });
  7998. };
  7999. })(method);
  8000. }
  8001. })();
  8002. // EXPOSE
  8003. // SVG and VML are appended just before the EXPOSE line
  8004. // Even with AMD, Raphael should be defined globally
  8005. oldRaphael.was ? (g.win.Raphael = R) : (Raphael = R);
  8006. return R;
  8007. }));