- added `SVG.Style` which can be created with `style()` or `fontface()` (#517)
- added `EventTarget` which is a baseclass to get event abilities (#641)
- added `Dom` which is a baseclass to get dom abilities
+- added `round()` which lets you round attribues from a node
### Removed
- removed `SVG.Array.split()` function
* @copyright Wout Fierens <wout@mick-wout.com>
* @license MIT
*
-* BUILT: Thu Nov 08 2018 12:02:46 GMT+0100 (GMT+01:00)
+* BUILT: Thu Nov 08 2018 12:57:03 GMT+0100 (GMT+01:00)
*/;
var SVG = (function () {
'use strict';
element = makeInstance(element);
this.node.parentNode.replaceChild(element.node, this.node);
return element;
+ }
+ }, {
+ key: "round",
+ value: function round() {
+ var precision = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2;
+ var map$$1 = arguments.length > 1 ? arguments[1] : undefined;
+ var factor = Math.pow(10, precision);
+ var attrs = this.attr(); // If we have no map, build one from attrs
+
+ if (!map$$1) {
+ map$$1 = Object.keys(attrs);
+ } // Holds rounded attributes
+
+
+ var newAttrs = {};
+ map$$1.forEach(function (key) {
+ newAttrs[key] = Math.round(attrs[key] * factor) / factor;
+ });
+ this.attr(newAttrs);
+ return this;
} // Return id on string conversion
}, {
expect(g.defs() instanceof SVG.Defs).toBeTruthy()
})
})
+ describe('round()', function () {
+ it('round all attribues of a node to a specific precision', function () {
+ var rect = draw.rect(100.123456, 200.987654)
+
+ expect(rect.round(2).attr()).toEqual(jasmine.objectContaining({
+ width: 100.12,
+ height: 200.99
+ }))
+ })
+ it('round specified attributes of a node to a specific precision', function () {
+ var rect = draw.rect(100.123456, 200.987654)
+
+ expect(rect.round(2, ['width']).attr()).toEqual(jasmine.objectContaining({
+ width: 100.12,
+ height: 200.987654
+ }))
+ })
+ })
})
return element
}
+ round (precision = 2, map) {
+ const factor = 10 ** precision
+ const attrs = this.attr()
+
+ // If we have no map, build one from attrs
+ if (!map) {
+ map = Object.keys(attrs)
+ }
+
+ // Holds rounded attributes
+ const newAttrs = {}
+ map.forEach((key) => {
+ newAttrs[key] = Math.round(attrs[key] * factor) / factor
+ })
+
+ this.attr(newAttrs)
+ return this
+ }
+
// Return id on string conversion
toString () {
return this.id()