summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-04-08 10:08:36 +1000
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-04-08 10:08:36 +1000
commite4e7e11da50c8129bcf31de03a2849f323aa4299 (patch)
tree16f9f68a6fefb2116f1e022242ee36943982cb9c /src
parenta4a532d5b886d1e59a96cee7453f3b2ffb8f9285 (diff)
downloadsvg.js-e4e7e11da50c8129bcf31de03a2849f323aa4299.tar.gz
svg.js-e4e7e11da50c8129bcf31de03a2849f323aa4299.zip
fix defs and reference, tests for Element
Diffstat (limited to 'src')
-rw-r--r--src/elements/Element.js19
-rw-r--r--src/types/Box.js10
2 files changed, 15 insertions, 14 deletions
diff --git a/src/elements/Element.js b/src/elements/Element.js
index d75db17..bb11611 100644
--- a/src/elements/Element.js
+++ b/src/elements/Element.js
@@ -1,4 +1,4 @@
-import { bbox, rbox } from '../types/Box.js'
+import { bbox, rbox, inside } from '../types/Box.js'
import { ctm, screenCTM } from '../types/Matrix.js'
import {
extend,
@@ -52,7 +52,8 @@ export default class Element extends Dom {
// Get defs
defs () {
- return this.root().defs()
+ const root = this.root()
+ return root && root.defs()
}
// Relative move over x and y axes
@@ -85,16 +86,6 @@ export default class Element extends Dom {
return this.attr('height', height)
}
- // Checks whether the given point inside the bounding box of the element
- inside (x, y) {
- const box = this.bbox()
-
- return x > box.x
- && y > box.y
- && x < box.x + box.width
- && y < box.y + box.height
- }
-
// Move element to given x and y values
move (x, y) {
return this.x(x).y(y)
@@ -126,7 +117,7 @@ export default class Element extends Dom {
attr = this.attr(attr)
if (!attr) return null
- const m = attr.match(reference)
+ const m = (attr + '').match(reference)
return m ? makeInstance(m[1]) : null
}
@@ -174,7 +165,7 @@ export default class Element extends Dom {
}
extend(Element, {
- bbox, rbox, point, ctm, screenCTM
+ bbox, rbox, inside, point, ctm, screenCTM
})
register(Element, 'Element')
diff --git a/src/types/Box.js b/src/types/Box.js
index 6d7d8a9..ae0f2cd 100644
--- a/src/types/Box.js
+++ b/src/types/Box.js
@@ -148,6 +148,16 @@ export function rbox (el) {
return box.addOffset()
}
+// Checks whether the given point is inside the bounding box
+export function inside (x, y) {
+ const box = this.bbox()
+
+ return x > box.x
+ && y > box.y
+ && x < box.x + box.width
+ && y < box.y + box.height
+}
+
registerMethods({
viewbox: {
viewbox (x, y, width, height) {