summaryrefslogtreecommitdiffstats
path: root/src/elements/G.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-12-12 23:21:10 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-12-12 23:21:10 +0100
commit33e82b796e7870a9523b6e9653877a2613f8f7a2 (patch)
tree7450136c1178008d9ba17bc2408ee5f43c71e9c4 /src/elements/G.js
parent7b02d60829d1151a9fd1e726a0a995b92b165328 (diff)
downloadsvg.js-33e82b796e7870a9523b6e9653877a2613f8f7a2.tar.gz
svg.js-33e82b796e7870a9523b6e9653877a2613f8f7a2.zip
Release 3.0.53.0.5
Diffstat (limited to 'src/elements/G.js')
-rw-r--r--src/elements/G.js66
1 files changed, 51 insertions, 15 deletions
diff --git a/src/elements/G.js b/src/elements/G.js
index 0a11c1e..8171fed 100644
--- a/src/elements/G.js
+++ b/src/elements/G.js
@@ -1,44 +1,80 @@
import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
+import { proportionalSize } from '../utils/utils.js'
import { registerMethods } from '../utils/methods.js'
import Container from './Container.js'
+import SVGNumber from '../types/SVGNumber.js'
export default class G extends Container {
constructor (node) {
super(nodeOrNew('g', node), node)
}
- x (x) {
- if (x == null) return this.transform()['x']
- return this.move(x, 0)
+ x (x, box = this.bbox()) {
+ if (x == null) return box.x
+
+ this.children().dx(x - box.x)
+ return this
}
- y (y) {
- if (y == null) return this.transform()['y']
- return this.move(0, y)
+ y (y, box = this.bbox()) {
+ if (y == null) return box.y
+
+ this.children().dy(y - box.y)
+ return this
}
move (x, y) {
- return this.translate(x, y)
+ const box = this.bbox()
+ return this.x(x, box).y(y, box)
}
dx (dx) {
- return this.transform({ dx }, true)
+ return this.children().dx(dx)
}
dy (dy) {
- return this.transform({ dy }, true)
+ return this.children().dy(dy)
}
- dmove (dx, dy) {
- return this.transform({ dx, dy }, true)
+ width (width, box = this.bbox()) {
+ if (width == null) return box.width
+
+ const scale = width / box.width
+
+ this.each(function () {
+ const _width = this.width()
+ const _x = this.x()
+
+ this.width(_width * scale)
+ this.x((_x - box.x) * scale + box.x)
+ })
+
+ return this
}
- width () {
- return this.bbox().width
+ height (height, box = this.bbox()) {
+ if (height == null) return box.height
+
+ const scale = height / box.height
+
+ this.each(function () {
+ const _height = this.height()
+ const _y = this.y()
+
+ this.height(_height * scale)
+ this.y((_y - box.y) * scale + box.y)
+ })
+
+ return this
}
- height () {
- return this.bbox().height
+ size (width, height) {
+ const box = this.bbox()
+ const p = proportionalSize(this, width, height, box)
+
+ return this
+ .width(new SVGNumber(p.width), box)
+ .height(new SVGNumber(p.height), box)
}
}