From 7523fb951aabc24bf290028c348cbe46bd846f86 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 23 Jan 2012 22:22:02 +0000 Subject: graphing with raphael --- test/where/raphael-svg-import.js | 878 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 878 insertions(+) create mode 100644 test/where/raphael-svg-import.js (limited to 'test/where/raphael-svg-import.js') diff --git a/test/where/raphael-svg-import.js b/test/where/raphael-svg-import.js new file mode 100644 index 0000000..a330792 --- /dev/null +++ b/test/where/raphael-svg-import.js @@ -0,0 +1,878 @@ + + + + + + + + + raphael-svg-import.js at master from wout/raphael-svg-import - GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + +
+

+ wout / + raphael-svg-import +

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +

Latest commit to the master branch

+ +
+

+ updated raphael to 1.5.2 + +

+
+ commit 9d59748129 + +
+ + wout + authored + +
+
+
+ + + +
+ + + +
+
+ + +
+
+
+
+ Txt + 100644 + 102 lines (88 sloc) + 2.728 kb +
+ +
+
+ + + + + +
+
1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
+100
+101
+102
+
+
+
/*
* Raphael SVG Import 0.0.4 - Extension to Raphael JS
*
* Copyright (c) 2011 Wout Fierens
* - Load order fix by Georgi Momchilov
* - Prototype dependency removed by Matt Cook
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
*/
Raphael.fn.importSVG = function (rawSVG, set) {
  try {
    if (typeof rawSVG === 'undefined')
      throw 'No data was provided.';
    
    rawSVG = rawSVG.replace(/\n|\r|\t/gi, '');
    
    if (!rawSVG.match(/<svg(.*?)>(.*)<\/svg>/i))
      throw "The data you entered doesn't contain valid SVG.";
    
    var findAttr = new RegExp('([a-z\-]+)="(.*?)"','gi'),
        findStyle = new RegExp('([a-z\-]+) ?: ?([^ ;]+)[ ;]?','gi'),
        findNodes = new RegExp('<(rect|polyline|circle|ellipse|path|polygon|image|text).*?\/>','gi');
    
    while(match = findNodes.exec(rawSVG)){
      var shape, style,
          attr = { 'fill':'#000' },
          node = RegExp.$1;
      
      while(findAttr.exec(match)){
        switch(RegExp.$1) {
          case 'stroke-dasharray':
            attr[RegExp.$1] = '- ';
          break;
          case 'style':
            style = RegExp.$2;
          break;
          default:
            attr[RegExp.$1] = RegExp.$2;
          break;
        }
      };
      
      if (typeof attr['stroke-width'] === 'undefined')
        attr['stroke-width'] = (typeof attr['stroke'] === 'undefined' ? 0 : 1);
      
      if (style)
        while(findStyle.exec(style))
          attr[RegExp.$1] = RegExp.$2;
      
      switch(node) {
        case 'rect':
          shape = this.rect();
        break;
        case 'circle':
          shape = this.circle();
        break;
        case 'ellipse':
          shape = this.ellipse();
        break;
        case 'path':
          shape = this.path(attr['d']);
        break;
        case 'polygon':
          shape = this.polygon(attr['points']);
        break;
        case 'image':
          shape = this.image();
        break;
        //-F case 'text':
        //-F shape = this.text();
        //-F break;
      }
      
      shape.attr(attr);
      
      if (typeof set !== 'undefined')
        set.push(shape);
    };
  } catch (error) {
    alert('The SVG data you entered was invalid! (' + error + ')');
  }
};

// extending raphael with a polygon function
Raphael.fn.polygon = function(pointString) {
  var poly = ['M'],
      point = pointString.split(' ');
      
  for(var i=0; i < point.length; i++) {
     var c = point[i].split(',');
     for(var j=0; j < c.length; j++) {
        var d = parseFloat(c[j]);
        if (d)
          poly.push(d);
     };
     if (i == 0)
      poly.push('L');
  }
  poly.push('Z');
  
  return this.path(poly);
};

+
+
+ +
+
+
+
+ +
+ + + +
+
+ + + + + + + + + +
+

Markdown Cheat Sheet

+ +
+ +
+
+

Format Text

+

Headers

+
+# This is an <h1> tag
+## This is an <h2> tag
+###### This is an <h6> tag
+

Text styles

+
+*This text will be italic*
+_This will also be italic_
+**This text will be bold**
+__This will also be bold__
+
+*You **can** combine them*
+
+
+
+

Lists

+

Unordered

+
+* Item 1
+* Item 2
+  * Item 2a
+  * Item 2b
+

Ordered

+
+1. Item 1
+2. Item 2
+3. Item 3
+   * Item 3a
+   * Item 3b
+
+
+

Miscellaneous

+

Images

+
+![GitHub Logo](/images/logo.png)
+Format: ![Alt Text](url)
+
+

Links

+
+http://github.com - automatic!
+[GitHub](http://github.com)
+

Blockquotes

+
+As Kanye West said:
+
+> We're living the future so
+> the present is our past.
+
+
+
+
+ +

Code Examples in Markdown

+
+

Syntax highlighting with GFM

+
+```javascript
+function fancyAlert(arg) {
+  if(arg) {
+    $.facebox({div:'#foo'})
+  }
+}
+```
+
+
+

Or, indent your code 4 spaces

+
+Here is a Python code example
+without syntax highlighting:
+
+    def foo:
+      if not bar:
+        return true
+
+
+

Inline code for comments

+
+I think you should use an
+`<addr>` element here instead.
+
+
+ +
+ + + +
+ +
+

Something went wrong with that request. Please try again. Dismiss

+
+ + + + + + + -- cgit v1.2.3