summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2019-05-09 15:08:51 +0200
committerGitHub <noreply@github.com>2019-05-09 15:08:51 +0200
commit6c7a7a02a7d6e90d5d5a7606cd4c8355cdae0fe5 (patch)
tree6df52e5ecae70495e4155f3e9e655cb3c8ed8425
parent1938355670b6dc9acf29199fb381e51bf1b72a70 (diff)
parent94d019ee3c8ff8439aeebc2380246c3ea01ed058 (diff)
downloadsvg.js-6c7a7a02a7d6e90d5d5a7606cd4c8355cdae0fe5.tar.gz
svg.js-6c7a7a02a7d6e90d5d5a7606cd4c8355cdae0fe5.zip
Merge pull request #992 from valentinradu/master
Fixed path transformation when box width or height is 0
-rw-r--r--spec/spec/path.js9
-rw-r--r--src/types/PathArray.js5
2 files changed, 14 insertions, 0 deletions
diff --git a/spec/spec/path.js b/spec/spec/path.js
index 9a78b25..28780c9 100644
--- a/spec/spec/path.js
+++ b/spec/spec/path.js
@@ -164,6 +164,15 @@ describe('Path', function() {
expect(path.height()).toBe(525)
expect(path.width() / path.height()).toBeCloseTo(box.width / box.height)
})
+ it('doesn\'t scale width/height when their value is 0', function() {
+ path = draw.path('M0 0L0 100')
+ path.size(500, 500)
+ expect(path.attr('d')).toBe('M0 0L0 500 ')
+
+ path = draw.path('M0 0L100 0')
+ path.size(500, 500)
+ expect(path.attr('d')).toBe('M0 0L500 0 ')
+ })
})
describe('scale()', function() {
diff --git a/src/types/PathArray.js b/src/types/PathArray.js
index 764d05c..56df5b6 100644
--- a/src/types/PathArray.js
+++ b/src/types/PathArray.js
@@ -182,6 +182,11 @@ extend(PathArray, {
var box = this.bbox()
var i, l
+ // If the box width or height is 0 then we ignore
+ // transformations on the respective axis
+ box.width = box.width === 0 ? 1 : box.width
+ box.height = box.height === 0 ? 1 : box.height
+
// recalculate position of all points according to new size
for (i = this.length - 1; i >= 0; i--) {
l = this[i][0]