diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2016-02-10 21:23:48 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2016-02-10 21:23:48 +0100 |
commit | 64784ffc12d1c4cffd23cd94a5430e3fc1544861 (patch) | |
tree | f19e17e492ee2b4127fe7c37ac377de3b4096ff7 | |
parent | a794401cda156048d921c575ac180aa704d0cd6c (diff) | |
parent | 2bf4788597959684f39e3e17777149a9ccb8ceab (diff) | |
download | svg.js-64784ffc12d1c4cffd23cd94a5430e3fc1544861.tar.gz svg.js-64784ffc12d1c4cffd23cd94a5430e3fc1544861.zip |
Merge branch 'master' into 3.0.0
-rw-r--r-- | CHANGELOG.md | 14 | ||||
-rw-r--r-- | README.md | 15 | ||||
-rw-r--r-- | gulpfile.js | 1 | ||||
-rw-r--r-- | spec/spec/element.js | 80 | ||||
-rw-r--r-- | spec/spec/group.js | 24 | ||||
-rw-r--r-- | spec/spec/point.js | 120 | ||||
-rw-r--r-- | spec/spec/regex.js | 53 | ||||
-rw-r--r-- | spec/spec/text.js | 35 | ||||
-rw-r--r-- | src/element.js | 4 | ||||
-rw-r--r-- | src/fx.js | 2 | ||||
-rw-r--r-- | src/group.js | 6 | ||||
-rw-r--r-- | src/matrix.js | 2 | ||||
-rw-r--r-- | src/number.js | 17 | ||||
-rw-r--r-- | src/point.js | 72 | ||||
-rw-r--r-- | src/regex.js | 6 | ||||
-rw-r--r-- | src/text.js | 2 | ||||
-rw-r--r-- | src/transform.js | 4 |
17 files changed, 385 insertions, 72 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d08f561..ac08aa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,19 @@ - added `precision()` method to round numeric element attributes -> __TODO!__ - added specs for `SVG.FX` -> __TODO!__ -# 2.2.4 (12/12/2014) +# 2.3.0 +- added `SVG.Point` which serves as Wrapper to the native `SVGPoint` (#437) +- added `element.point(x,y)` which transforms a point from screen coordinates to the elements space (#403) +- fixed `svgjs:data` attribute which was not set properly in all browsers (#428) +- fixed `isNumber` and `numberAndUnit` regex (#405) +- fixed error where a parent node is not found when loading an image but the canvas was cleared (#447) + +# 2.2.5 (29/12/2015) +- added check for existence of node (#431) +- `group.move()` now allows string numbers as input (#433) +- `matrixify()` will not apply the calculated matrix to the node anymore + +# 2.2.4 (12/12/2015) - fixed `transform()` which returns the matrix values (a-f) now, too (#423) - double newlines (\n\n) are correctly handled as blank line from `text()` - fixed use of scrollX vs pageXOffset in `rbox()` (#425) @@ -228,7 +228,7 @@ _Javascript inheritance stack: `SVG.Circle` < `SVG.Shape` < `SVG.Element`_ Circles can also be redefined by their radius: ```javascript -rect.radius(75) +circle.radius(75) ``` __`returns`: `itself`__ @@ -248,7 +248,7 @@ _Javascript inheritance stack: `SVG.Ellipse` < `SVG.Shape` < `SVG.Element`_ Ellipses can also be redefined by their radii: ```javascript -rect.radius(75, 50) +ellipse.radius(75, 50) ``` __`returns`: `itself`__ @@ -1918,6 +1918,17 @@ path.matrixify() __`returns`: `SVG.Matrix`__ +### point() +Transforms a point from screen coordinates to the elements coordinate system + +```javascript +// e is some mouseevent +var point = path.point(e.screeX, e.screenY) // {x, y} +``` + +__`returns`: `SVG.Point`__ + + ### inside() To check if a given point is inside the bounding box of an element you can use the `inside()` method: diff --git a/gulpfile.js b/gulpfile.js index 476dc00..7edc71f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -44,6 +44,7 @@ var parts = [ , 'src/fxnew.js'
, 'src/boxes.js'
, 'src/matrix.js'
+, 'src/point.js'
, 'src/attr.js'
, 'src/transform.js'
, 'src/style.js'
diff --git a/spec/spec/element.js b/spec/spec/element.js index 10b8b75..96a5ff7 100644 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -1,5 +1,5 @@ describe('Element', function() { - + beforeEach(function() { draw.attr('viewBox', null) }) @@ -7,7 +7,7 @@ describe('Element', function() { afterEach(function() { draw.clear() }) - + it('should create a circular reference on the node', function() { var rect = draw.rect(100,100) expect(rect.node.instance).toBe(rect) @@ -19,10 +19,10 @@ describe('Element', function() { expect(rect.native()).toBe(rect.node) }) }) - + describe('attr()', function() { var rect - + beforeEach(function() { rect = draw.rect(100,100) }) @@ -103,11 +103,11 @@ describe('Element', function() { describe('id()', function() { var rect - + beforeEach(function() { rect = draw.rect(100,100) }) - + it('gets the value if the id attribute without an argument', function() { expect(rect.id()).toBe(rect.attr('id')) }) @@ -116,7 +116,7 @@ describe('Element', function() { expect(rect.attr('id')).toBe('new_id') }) }) - + describe('style()', function() { it('sets the style with key and value arguments', function() { var rect = draw.rect(100,100).style('cursor', 'crosshair') @@ -149,14 +149,14 @@ describe('Element', function() { expect(rect.style()).toBe('') }) }) - + describe('transform()', function() { var rect, ctm - + beforeEach(function() { rect = draw.rect(100,100) }) - + it('gets the current transformations', function() { expect(rect.transform()).toEqual(new SVG.Matrix(rect).extract()) }) @@ -246,7 +246,7 @@ describe('Element', function() { describe('untransform()', function() { var circle - + beforeEach(function() { circle = draw.circle(100).translate(50, 100) }) @@ -265,11 +265,11 @@ describe('Element', function() { describe('ctm()', function() { var rect - + beforeEach(function() { rect = draw.rect(100, 100) }) - + it('gets the current transform matrix of the element', function() { rect.translate(10, 20) expect(rect.ctm().toString()).toBe('matrix(1,0,0,1,10,20)') @@ -278,7 +278,7 @@ describe('Element', function() { expect(rect.ctm() instanceof SVG.Matrix).toBeTruthy() }) }) - + describe('data()', function() { it('sets a data attribute and convert value to json', function() { var rect = draw.rect(100,100).data('test', 'value') @@ -310,10 +310,10 @@ describe('Element', function() { it('maintains data type for an object', function() { var rect = draw.rect(100,100).data('test', { string: 'value', array: [1,2,3] }) expect(typeof rect.data('test')).toBe('object') - expect(Array.isArray(rect.data('test').array)).toBe(true) + expect(Array.isArray(rect.data('test').array)).toBe(true) }) }) - + describe('remove()', function() { it('removes an element and return it', function() { var rect = draw.rect(100,100) @@ -345,7 +345,7 @@ describe('Element', function() { expect(rect.parent()).toBe(group) }) }) - + describe('rbox()', function() { it('returns an instance of SVG.RBox', function() { var rect = draw.rect(100,100) @@ -372,14 +372,14 @@ describe('Element', function() { expect(box.height).toBe(210) }) }) - + describe('doc()', function() { it('returns the parent document', function() { var rect = draw.rect(100,100) expect(rect.doc()).toBe(draw) }) }) - + describe('parent()', function() { it('contains the parent svg', function() { var rect = draw.rect(100,100) @@ -402,7 +402,7 @@ describe('Element', function() { expect(rect.parent('.test')).toBe(group1) }) }) - + describe('parents()', function() { it('returns array of parent up to but not including the dom element filtered by type', function() { var group1 = draw.group().addClass('test') @@ -415,7 +415,7 @@ describe('Element', function() { expect(rect.parents().length).toBe(3) }) }) - + describe('clone()', function() { var rect, group, circle @@ -463,20 +463,20 @@ describe('Element', function() { var rectIndex = draw.children().indexOf(rect) rect.replace(circle) - + expect(rectIndex).toBe(draw.children().indexOf(circle)) }) it('removes the original element', function() { var rect = draw.rect(100,100).center(321,567).fill('#f06') rect.replace(draw.circle(200)) - + expect(draw.has(rect)).toBe(false) }) it('returns the new element', function() { var circle = draw.circle(200) var element = draw.rect(100,100).center(321,567).fill('#f06').replace(circle) - + expect(element).toBe(circle) }) }) @@ -616,4 +616,36 @@ describe('Element', function() { }) }) }) + + describe('writeDataToDom()', function() { + it('set all properties in el.dom to the svgjs:data attribute', function(){ + var rect = draw.rect(100,100) + rect.dom.foo = 'bar' + rect.dom.number = new SVG.Number('3px') + + rect.writeDataToDom() + + expect(rect.attr('svgjs:data')).toBe('{"foo":"bar","number":"3px"}') + }) + }) + + describe('setData()', function() { + it('read all data from the svgjs:data attribute and assign it to el.dom', function(){ + var rect = draw.rect(100,100) + + rect.attr('svgjs:data', '{"foo":"bar","number":"3px"}') + rect.setData(JSON.parse(rect.attr('svgjs:data'))) + + expect(rect.dom.foo).toBe('bar') + expect(rect.dom.number).toBe('3px') + }) + }) + + describe('point()', function() { + it('creates a point from screen coordinates transformed in the elements space', function(){ + var rect = draw.rect(100,100) + expect(rect.point(2,5).x).toBeCloseTo(-6) + expect(rect.point(2,5).y).toBeCloseTo(-3) + }) + }) }) diff --git a/spec/spec/group.js b/spec/spec/group.js index 88772e0..63335ae 100644 --- a/spec/spec/group.js +++ b/spec/spec/group.js @@ -5,7 +5,7 @@ describe('Group', function() { group = draw.group().move(50, 50) group.rect(100,100) }) - + afterEach(function() { draw.clear() }) @@ -24,8 +24,13 @@ describe('Group', function() { var box = group.gbox() expect(box.x).toBe(13) }) + it('sets the value of x correctly when the first argument is a string number', function(){ + group.x('123') + var box = group.gbox() + expect(box.x).toBe(123) + }) }) - + describe('y()', function() { it('returns the value of y without an argument', function() { expect(group.y()).toBe(50) @@ -40,8 +45,13 @@ describe('Group', function() { var box = group.gbox() expect(box.y).toBe(15) }) + it('sets the value of y correctly when the first argument is a string number', function(){ + group.y('124') + var box = group.gbox() + expect(box.y).toBe(124) + }) }) - + describe('cx()', function() { it('returns the value of cx without an argument', function() { expect(group.cx()).toBe(100) @@ -52,7 +62,7 @@ describe('Group', function() { expect(box.cx).toBe(123) }) }) - + describe('cy()', function() { it('returns the value of cy without an argument', function() { expect(group.cy()).toBe(100) @@ -70,7 +80,7 @@ describe('Group', function() { expect(group.node.getAttribute('transform')).toBe('matrix(1,0,0,1,123,456)') }) }) - + describe('center()', function() { it('sets the cx and cy position', function() { group.center(321,567) @@ -103,6 +113,6 @@ describe('Group', function() { expect(group.node.getAttribute('transform')).toBe('matrix(1,0,0,1,130,85)') }) }) - -})
\ No newline at end of file + +}) diff --git a/spec/spec/point.js b/spec/spec/point.js new file mode 100644 index 0000000..ce28781 --- /dev/null +++ b/spec/spec/point.js @@ -0,0 +1,120 @@ +describe('Point', function() { + var point + + describe('initialization', function() { + + describe('without a source', function() { + + point(function() { + matrix = new SVG.Point + }) + + it('creates a new point with default values', function() { + expect(point.x).toBe(0) + expect(point.y).toBe(0) + }) + + }) + + describe('with x and y given', function() { + it('creates a point with given values', function() { + var point = new SVG.Point(2,4) + + expect(point.x).toBe(2) + expect(point.y).toBe(4) + }) + }) + + describe('with array given', function() { + it('creates a point from array', function() { + var point = new SVG.Point([2,4]) + + expect(point.x).toBe(2) + expect(point.y).toBe(4) + }) + }) + + describe('with object given', function() { + it('creates a point from object', function() { + var point = new SVG.Point({x:2,y:4}) + + expect(point.x).toBe(2) + expect(point.y).toBe(4) + }) + }) + + describe('with SVG.Point given', function() { + it('creates a point from SVG.Point', function() { + var point = new SVG.Point(new SVG.Point(2,4)) + + expect(point.x).toBe(2) + expect(point.y).toBe(4) + }) + }) + + describe('with native SVGPoint given', function() { + it('creates a point from native SVGPoint', function() { + var point = new SVG.Point(new SVG.Point(2,4).native()) + + expect(point.x).toBe(2) + expect(point.y).toBe(4) + }) + }) + + }) + + describe('clone()', function() { + it('returns cloned point', function() { + var point1 = new SVG.Point(1,1) + , point2 = new SVG.Point(point1) + + expect(point1).toEqual(point2) + expect(point1).not.toBe(point2) + }) + }) + + describe('morph()', function() { + it('stores a given point for morphing', function() { + var point1 = new SVG.Point(1,1) + , point2 = new SVG.Matrix(2,2) + + point1.morph(point2) + + expect(point1.destination).toEqual(point2) + }) + it('stores a clone, not the given matrix itself', function() { + var point1 = new SVG.Point(1,1) + , point2 = new SVG.Matrix(2,2) + + point1.morph(point2) + + expect(point1.destination).not.toBe(point2) + }) + }) + + describe('at()', function() { + it('returns a morphed point at a given position', function() { + var point1 = new SVG.Point(1,1) + , point2 = new SVG.Point(2,2) + , matrix3 = matrix1.morph(matrix2).at(0.5) + + expect(matrix3).toEqual(new SVG.Point(1.5, 1.5)) + }) + }) + + describe('transform()', function() { + it('returns a point transformed with given matrix', function() { + var point = new SVG.Point(1,5) + , matrix = new SVG.Matrix(0,0,1,0,0,1) + + expect(point.transform(matrox)).toEqual(new SVG.Point(5,1)) + }) + } + + describe('native()', function() { + it('returns native SVGPoint', function() { + expect(new SVG.Point().native() instanceof SVGPoint).toBeTruthy() + }) + }) + +})
\ No newline at end of file diff --git a/spec/spec/regex.js b/spec/spec/regex.js index f017059..9a14bec 100644 --- a/spec/spec/regex.js +++ b/spec/spec/regex.js @@ -1,23 +1,46 @@ describe('Regex', function() { describe('matchers', function() { - describe('unit', function() { + + describe('numberAndUnit', function() { var match it('is true with a positive unit value', function() { - match = ('10%').match(SVG.regex.unit) + match = ('10%').match(SVG.regex.numberAndUnit) expect(match[1]).toBe('10') - expect(match[2]).toBe('%') + expect(match[5]).toBe('%') }) it('is true with a negative unit value', function() { - match = ('-11%').match(SVG.regex.unit) + match = ('-11%').match(SVG.regex.numberAndUnit) expect(match[1]).toBe('-11') - expect(match[2]).toBe('%') + expect(match[5]).toBe('%') }) it('is false with a positive unit value', function() { - match = ('NotAUnit').match(SVG.regex.unit) + match = ('NotAUnit').match(SVG.regex.numberAndUnit) expect(match).toBeNull() }) + + it('is true with a number', function() { + ["1", "-1", "+15", "1.55", ".5", "5.", "1.3e2", "1E-4", "1e+12"].forEach(function(s) { + expect(SVG.regex.numberAndUnit.test(s)).toBeTruthy() + }) + }) + it('is false with a faulty number', function() { + ["+-1", "1.2.3", "1+1", "1e4.5", ".5.", "1f5", "."].forEach(function(s) { + expect(SVG.regex.numberAndUnit.test(s)).toBeFalsy() + }) + }) + it('is true with a number with unit', function() { + ["1px", "-1em", "+15%", "1.55s", ".5pt", "5.deg", "1.3e2rad", "1E-4grad", "1e+12cm"].forEach(function(s) { + expect(SVG.regex.numberAndUnit.test(s)).toBeTruthy() + }) + }) + it('is false with a faulty number or wrong unit', function() { + ["1em1", "-1eq,5"].forEach(function(s) { + expect(SVG.regex.numberAndUnit.test(s)).toBeFalsy() + }) + }) + }) }) @@ -46,6 +69,24 @@ describe('Regex', function() { }) }) + describe('isNumber', function() { + + it('is true with a number', function() { + ["1", "-1", "+15", "1.55", ".5", "5.", "1.3e2", "1E-4", "1e+12"].forEach(function(s) { + expect(SVG.regex.isNumber.test(s)).toBeTruthy() + }) + }) + + it('is false with a faulty number', function() { + ["1a", "+-1", "1.2.3", "1+1", "1e4.5", ".5.", "1f5", "."].forEach(function(s) { + expect(SVG.regex.isNumber.test(s)).toBeFalsy() + }) + }) + + }) + + + }) })
\ No newline at end of file diff --git a/spec/spec/text.js b/spec/spec/text.js index 39fba10..b60a97d 100644 --- a/spec/spec/text.js +++ b/spec/spec/text.js @@ -4,15 +4,15 @@ describe('Text', function() { var text - + beforeEach(function() { text = draw.text(loremIpsum).size(5) }) - + afterEach(function() { draw.clear() }) - + describe('x()', function() { it('returns the value of x without an argument', function() { expect(text.x()).toBe(0) @@ -28,7 +28,7 @@ describe('Text', function() { expect(box.x).toBeCloseTo(123) }) }) - + describe('y()', function() { it('returns the value of y without an argument', function() { expect(text.y(0).y()).toBe(0) @@ -46,7 +46,7 @@ describe('Text', function() { expect(text.node.getAttribute('y')).toBe('40%') }) }) - + describe('cx()', function() { it('returns the value of cx without an argument', function() { var box = text.bbox() @@ -63,7 +63,7 @@ describe('Text', function() { expect(box.cx).toBeCloseTo(123) }) }) - + describe('cy()', function() { it('returns the value of cy without an argument', function() { var box = text.bbox() @@ -75,7 +75,7 @@ describe('Text', function() { expect(Math.round(box.cy * 10) / 10).toBe(345) }) }) - + describe('move()', function() { it('sets the x and y position', function() { text.move(123,456) @@ -84,7 +84,7 @@ describe('Text', function() { expect(box.y).toBeCloseTo(456) }) }) - + describe('center()', function() { it('sets the cx and cy position', function() { text.center(321, 567) @@ -93,7 +93,7 @@ describe('Text', function() { expect(box.cy).toBeCloseTo(567, 1) }) }) - + describe('size()', function() { it('should define the width and height of the element', function() { text.size(50) @@ -212,7 +212,7 @@ describe('Text', function() { expect(text.length()).toBeCloseTo(text.lines().get(0).length() + text.lines().get(1).length() + text.lines().get(2).length(), 3) }) }) - + describe('build()', function() { it('enables adding multiple plain text nodes when given true', function() { text.clear().build(true) @@ -243,7 +243,20 @@ describe('Text', function() { expect(text.node.childNodes[1]).toBe(undefined) }) }) - + + describe('setData()', function() { + it('read all data from the svgjs:data attribute and assign it to el.dom', function(){ + + text.attr('svgjs:data', '{"foo":"bar","leading":"3px"}') + text.setData(JSON.parse(text.attr('svgjs:data'))) + + expect(text.dom.foo).toBe('bar') + expect(text.dom.leading instanceof SVG.Number).toBeTruthy() + expect(text.dom.leading.value).toBe(3) + expect(text.dom.leading.unit).toBe('px') + }) + }) + }) diff --git a/src/element.js b/src/element.js index bd5d08d..75d77dc 100644 --- a/src/element.js +++ b/src/element.js @@ -171,7 +171,7 @@ SVG.Element = SVG.invent({ if(!type) return parent // loop trough ancestors if type is given - while(parent.node instanceof SVGElement){ + while(parent && parent.node instanceof SVGElement){ if(typeof type === 'string' ? parent.matches(type) : parent instanceof type) return parent parent = SVG.adopt(parent.node.parentNode) } @@ -247,7 +247,7 @@ SVG.Element = SVG.invent({ this.node.removeAttribute('svgjs:data') if(Object.keys(this.dom).length) - this.node.setAttributeNS(SVG.svgjs, 'svgjs:data', JSON.stringify(this.dom)) + this.node.setAttribute('svgjs:data', JSON.stringify(this.dom)) // see #428 return this } @@ -246,7 +246,7 @@ SVG.FX = SVG.invent({ this.attrs[a] = SVG.Color.isColor(v) ? // prepare color for morphing new SVG.Color(from).morph(v) : - SVG.regex.unit.test(v) ? + SVG.regex.numberAndUnit.test(v) ? // prepare number for morphing new SVG.Number(from).morph(v) : // prepare for plain morphing diff --git a/src/group.js b/src/group.js index df5c001..05d144c 100644 --- a/src/group.js +++ b/src/group.js @@ -9,11 +9,11 @@ SVG.G = SVG.invent({ , extend: { // Move over x-axis x: function(x) { - return x == null ? this.transform('x') : this.transform({ x: -this.x() + x }, true) + return x == null ? this.transform('x') : this.transform({ x: x - this.x() }, true) } // Move over y-axis , y: function(y) { - return y == null ? this.transform('y') : this.transform({ y: -this.y() + y }, true) + return y == null ? this.transform('y') : this.transform({ y: y - this.y() }, true) } // Move by center over x-axis , cx: function(x) { @@ -47,4 +47,4 @@ SVG.G = SVG.invent({ return this.put(new SVG.G) } } -})
\ No newline at end of file +}) diff --git a/src/matrix.js b/src/matrix.js index 4358e55..9b3c28e 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -183,4 +183,4 @@ SVG.Matrix = SVG.invent({ } -})
\ No newline at end of file +}) diff --git a/src/number.js b/src/number.js index 0ca8831..8eb7a1c 100644 --- a/src/number.js +++ b/src/number.js @@ -12,20 +12,20 @@ SVG.Number = SVG.invent({ this.value = isNaN(value) ? 0 : !isFinite(value) ? (value < 0 ? -3.4e+38 : +3.4e+38) : value } else if (typeof value === 'string') { - unit = value.match(SVG.regex.unit) + unit = value.match(SVG.regex.numberAndUnit) if (unit) { // make value numeric this.value = parseFloat(unit[1]) - + // normalize - if (unit[2] == '%') + if (unit[5] == '%') this.value /= 100 - else if (unit[2] == 's') + else if (unit[5] == 's') this.value *= 1000 - + // store unit - this.unit = unit[2] + this.unit = unit[5] } } else { @@ -48,6 +48,9 @@ SVG.Number = SVG.invent({ this.value ) + this.unit } + , toJSON: function() { + return this.toString() + } , // Convert to primitive valueOf: function() { return this.value @@ -71,7 +74,7 @@ SVG.Number = SVG.invent({ // Convert to different unit , to: function(unit) { var number = new SVG.Number(this) - + if (typeof unit === 'string') number.unit = unit diff --git a/src/point.js b/src/point.js new file mode 100644 index 0000000..ba7bd8f --- /dev/null +++ b/src/point.js @@ -0,0 +1,72 @@ +SVG.Point = SVG.invent({ + // Initialize + create: function(x,y) { + var i, source, base = {x:0, y:0} + + // ensure source as object + source = Array.isArray(x) ? + {x:x[0], y:x[1]} : + typeof x === 'object' ? + {x:x.x, y:x.y} : + y != null ? + {x:x, y:y} : base + + // merge source + this.x = source.x + this.y = source.y + } + + // Add methods +, extend: { + // Clone point + clone: function() { + return new SVG.Point(this) + } + // Morph one point into another + , morph: function(point) { + // store new destination + this.destination = new SVG.Point(point) + + return this + } + // Get morphed point at a given position + , at: function(pos) { + // make sure a destination is defined + if (!this.destination) return this + + // calculate morphed matrix at a given position + var point = new SVG.Point({ + x: this.x + (this.destination.x - this.x) * pos + , y: this.y + (this.destination.y - this.y) * pos + }) + + return point + } + // Convert to native SVGPoint + , native: function() { + // create new point + var point = SVG.parser.draw.node.createSVGPoint() + + // update with current values + point.x = this.x + point.y = this.y + + return point + } + // transform point with matrix + , transform: function(matrix) { + return new SVG.Point(this.native().matrixTransform(matrix.native())) + } + + } + +}) + +SVG.extend(SVG.Element, { + + // Get point + point: function(x, y) { + return new SVG.Point(x,y).transform(this.screenCTM().inverse()); + } + +}) diff --git a/src/regex.js b/src/regex.js index 1b26afd..265a11a 100644 --- a/src/regex.js +++ b/src/regex.js @@ -1,7 +1,7 @@ // Storage for regular expressions SVG.regex = { // Parse unit value - unit: /^(-?[\d\.]+)([a-z%]{0,2})$/ + numberAndUnit: /^([+-]?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?)([a-z%]*)$/i // Parse hex value , hex: /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i @@ -34,7 +34,7 @@ SVG.regex = { , isBlank: /^(\s+)?$/ // Test for numeric string -, isNumber: /^-?[\d\.]+$/ +, isNumber: /^[+-]?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i // Test for percent value , isPercent: /^-?[\d\.]+%$/ @@ -64,4 +64,4 @@ SVG.regex = { // matches X , X: /X/g -}
\ No newline at end of file +} diff --git a/src/text.js b/src/text.js index 79a4e1e..debc1fb 100644 --- a/src/text.js +++ b/src/text.js @@ -159,7 +159,7 @@ SVG.Text = SVG.invent({ // overwrite method from parent to set data properly , setData: function(o){ this.dom = o - this.dom.leading = o.leading ? new SVG.Number(o.leading.value, o.leading.unit) : new SVG.Number(1.3) + this.dom.leading = new SVG.Number(o.leading || 1.3) return this } } diff --git a/src/transform.js b/src/transform.js index 2d6429c..2b6e9df 100644 --- a/src/transform.js +++ b/src/transform.js @@ -125,7 +125,7 @@ SVG.extend(SVG.Element, { untransform: function() { return this.attr('transform', null) }, - // merge the whole transformation chain into one matrix + // merge the whole transformation chain into one matrix and returns it matrixify: function() { var matrix = (this.attr('transform') || '') @@ -142,8 +142,6 @@ SVG.extend(SVG.Element, { return matrix[transform[0]].apply(matrix, transform[1]) }, new SVG.Matrix()) - // apply calculated matrix to element - this.attr('transform', matrix) return matrix }, |