aboutsummaryrefslogtreecommitdiffstats
path: root/src/elements/Path.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-06 13:48:05 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-06 13:48:05 +0100
commita0b13ebcacfd74b9f521110c7225bb404325bcd3 (patch)
treea07c5cc422645e31d7dfef81ce4e54f03f0945f6 /src/elements/Path.js
parent9f2696e8a2cf7e4eebc1cc7e31027fe2070094fa (diff)
downloadsvg.js-a0b13ebcacfd74b9f521110c7225bb404325bcd3.tar.gz
svg.js-a0b13ebcacfd74b9f521110c7225bb404325bcd3.zip
reordered modules, add es6 build
Diffstat (limited to 'src/elements/Path.js')
-rw-r--r--src/elements/Path.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/elements/Path.js b/src/elements/Path.js
new file mode 100644
index 0000000..71be8a1
--- /dev/null
+++ b/src/elements/Path.js
@@ -0,0 +1,81 @@
+import { nodeOrNew, register } from '../utils/adopter.js'
+import { proportionalSize } from '../utils/utils.js'
+import { registerMethods } from '../utils/methods.js'
+import PathArray from '../types/PathArray.js'
+import Shape from './Shape.js'
+import baseFind from '../modules/core/selector.js'
+
+export default class Path extends Shape {
+ // Initialize node
+ constructor (node) {
+ super(nodeOrNew('path', node), Path)
+ }
+
+ // Get array
+ array () {
+ return this._array || (this._array = new PathArray(this.attr('d')))
+ }
+
+ // Plot new path
+ plot (d) {
+ return (d == null) ? this.array()
+ : this.clear().attr('d', typeof d === 'string' ? d : (this._array = new PathArray(d)))
+ }
+
+ // Clear array cache
+ clear () {
+ delete this._array
+ return this
+ }
+
+ // Move by left top corner
+ move (x, y) {
+ return this.attr('d', this.array().move(x, y))
+ }
+
+ // Move by left top corner over x-axis
+ x (x) {
+ return x == null ? this.bbox().x : this.move(x, this.bbox().y)
+ }
+
+ // Move by left top corner over y-axis
+ y (y) {
+ return y == null ? this.bbox().y : this.move(this.bbox().x, y)
+ }
+
+ // Set element size to given width and height
+ size (width, height) {
+ var p = proportionalSize(this, width, height)
+ return this.attr('d', this.array().size(p.width, p.height))
+ }
+
+ // Set width of element
+ width (width) {
+ return width == null ? this.bbox().width : this.size(width, this.bbox().height)
+ }
+
+ // Set height of element
+ height (height) {
+ return height == null ? this.bbox().height : this.size(this.bbox().width, height)
+ }
+
+ targets () {
+ return baseFind('svg textpath [href*="' + this.id() + '"]')
+ }
+}
+
+// Define morphable array
+Path.prototype.MorphArray = PathArray
+
+// Add parent method
+registerMethods({
+ Container: {
+ // Create a wrapped path element
+ path (d) {
+ // make sure plot is called as a setter
+ return this.put(new Path()).plot(d || new PathArray())
+ }
+ }
+})
+
+register(Path)