diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-06 13:48:05 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-06 13:48:05 +0100 |
commit | a0b13ebcacfd74b9f521110c7225bb404325bcd3 (patch) | |
tree | a07c5cc422645e31d7dfef81ce4e54f03f0945f6 /src/modules/core/circled.js | |
parent | 9f2696e8a2cf7e4eebc1cc7e31027fe2070094fa (diff) | |
download | svg.js-a0b13ebcacfd74b9f521110c7225bb404325bcd3.tar.gz svg.js-a0b13ebcacfd74b9f521110c7225bb404325bcd3.zip |
reordered modules, add es6 build
Diffstat (limited to 'src/modules/core/circled.js')
-rw-r--r-- | src/modules/core/circled.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/modules/core/circled.js b/src/modules/core/circled.js new file mode 100644 index 0000000..9a3b1ad --- /dev/null +++ b/src/modules/core/circled.js @@ -0,0 +1,64 @@ +// FIXME: import this to runner +import { proportionalSize } from '../../utils/utils.js' +import SVGNumber from '../../types/SVGNumber.js' + +// Radius x value +export function rx (rx) { + return this.attr('rx', rx) +} + +// Radius y value +export function ry (ry) { + return this.attr('ry', ry) +} + +// Move over x-axis +export function x (x) { + return x == null + ? this.cx() - this.rx() + : this.cx(x + this.rx()) +} + +// Move over y-axis +export function y (y) { + return y == null + ? this.cy() - this.ry() + : this.cy(y + this.ry()) +} + +// Move by center over x-axis +export function cx (x) { + return x == null + ? this.attr('cx') + : this.attr('cx', x) +} + +// Move by center over y-axis +export function cy (y) { + return y == null + ? this.attr('cy') + : this.attr('cy', y) +} + +// Set width of element +export function width (width) { + return width == null + ? this.rx() * 2 + : this.rx(new SVGNumber(width).divide(2)) +} + +// Set height of element +export function height (height) { + return height == null + ? this.ry() * 2 + : this.ry(new SVGNumber(height).divide(2)) +} + +// Custom size function +export function size (width, height) { + var p = proportionalSize(this, width, height) + + return this + .rx(new SVGNumber(p.width).divide(2)) + .ry(new SVGNumber(p.height).divide(2)) +} |