summaryrefslogtreecommitdiffstats
path: root/src/elements/Dom.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/elements/Dom.js')
-rw-r--r--src/elements/Dom.js28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/elements/Dom.js b/src/elements/Dom.js
index 0c4ecb3..6fd1b1b 100644
--- a/src/elements/Dom.js
+++ b/src/elements/Dom.js
@@ -194,22 +194,15 @@ export default class Dom extends EventTarget {
return element
}
- round (precision = 2, map) {
+ round (precision = 2, map = null) {
const factor = 10 ** precision
- const attrs = this.attr()
+ const attrs = this.attr(map)
- // If we have no map, build one from attrs
- if (!map) {
- map = Object.keys(attrs)
+ for (const i in attrs) {
+ attrs[i] = Math.round(attrs[i] * factor) / factor
}
- // Holds rounded attributes
- const newAttrs = {}
- map.forEach((key) => {
- newAttrs[key] = Math.round(attrs[key] * factor) / factor
- })
-
- this.attr(newAttrs)
+ this.attr(attrs)
return this
}
@@ -302,6 +295,17 @@ export default class Dom extends EventTarget {
return this
}
+ wrap (node) {
+ const parent = this.parent()
+
+ if (!parent) {
+ return node.put(this)
+ }
+
+ const position = parent.index(this)
+ return parent.put(node, position).put(this)
+ }
+
// write svgjs data to the dom
writeDataToDom () {
// dump variables recursively