From 050af98a7ada3280f02acf25fbaba585a264e68a Mon Sep 17 00:00:00 2001 From: wout Date: Wed, 5 Feb 2014 10:51:47 +0100 Subject: added pointAt() method to SVG.Path --- src/path.js | 5 +---- src/sugar.js | 40 ++++++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/path.js b/src/path.js index 76ef1ba..0345487 100755 --- a/src/path.js +++ b/src/path.js @@ -37,10 +37,7 @@ SVG.Path = SVG.invent({ , height: function(height) { return height == null ? this.bbox().height : this.size(this.bbox().width, height) } - // Get path length - , length: function() { - return this.node.getTotalLength() - } + } // Add parent method diff --git a/src/sugar.js b/src/sugar.js index 5d7f5aa..5c71afc 100755 --- a/src/sugar.js +++ b/src/sugar.js @@ -72,7 +72,6 @@ SVG.extend(SVG.Element, SVG.FX, { }) -// SVG.extend(SVG.Rect, SVG.Ellipse, { // Add x and y radius radius: function(x, y) { @@ -81,21 +80,30 @@ SVG.extend(SVG.Rect, SVG.Ellipse, { }) +SVG.extend(SVG.Path, { + // Get path length + length: function() { + return this.node.getTotalLength() + } + // Get point at length +, pointAt: function(length) { + return this.node.getPointAtLength(length) + } -if (SVG.Text) { - SVG.extend(SVG.Text, SVG.FX, { - // Set font - font: function(o) { - for (var key in o) - key == 'anchor' ? - this.attr('text-anchor', o[key]) : - _styleAttr.indexOf(key) > -1 ? - this.attr('font-'+ key, o[key]) : - this.attr(key, o[key]) - - return this - } +}) + +SVG.extend(SVG.Text, SVG.FX, { + // Set font + font: function(o) { + for (var key in o) + key == 'anchor' ? + this.attr('text-anchor', o[key]) : + _styleAttr.indexOf(key) > -1 ? + this.attr('font-'+ key, o[key]) : + this.attr(key, o[key]) - }) -} + return this + } + +}) -- cgit v1.2.3