summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md4
-rw-r--r--spec/spec/elements/Circle.js66
-rw-r--r--src/main.js5
-rw-r--r--src/modules/optional/sugar.js4
4 files changed, 72 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 54cb5bf..64c67e2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,7 +14,7 @@ The document follows the conventions described in [“Keep a CHANGELOG”](http:
- fixed positioning methods of `TSpan` to position them by its bounding box
- fixed `flip()` method which flips correctly by center by default now and accepts correct arguments
- fixed a case in `rbox()` where not always all values of the box were updated
- - fixed `getOrigin()` function used by `transform()` so that all origin (#1085) popssibilities specified in the docs are working
+ - fixed `getOrigin()` function used by `transform()` so that all origin popssibilities specified in the docs are working (#1085)
- fixed positioning of text by its baseline when using `amove()`
- fixed tons of typings in the svg.d.ts file and relaxed type requirements for `put()` and `parent()`
- fixed adopter when adopting an svg/html string. It had still its wrapper as parentNode attached
@@ -33,8 +33,8 @@ The document follows the conventions described in [“Keep a CHANGELOG”](http:
- added `orient()` method to `Marker`
- added `options` parameter to `dispatch()` and `fire()` to allow for more special needs
- added `newLine()` constructor to `Text` to create a tspan marked as new line (#1088)
- - added lots of tests in es6 format
- added `Fragment` as a wrapper for document-fragment
+ - added lots of tests in es6 format
## [3.0.16] - 2019-11-12
diff --git a/spec/spec/elements/Circle.js b/spec/spec/elements/Circle.js
new file mode 100644
index 0000000..e9b8b56
--- /dev/null
+++ b/spec/spec/elements/Circle.js
@@ -0,0 +1,66 @@
+/* globals describe, expect, it, beforeEach, spyOn, jasmine */
+
+import { Circle, G } from '../../../src/main.js'
+
+const { any, objectContaining } = jasmine
+
+describe('Circle.js', () => {
+ let circle
+
+ beforeEach(() => {
+ circle = new Circle()
+ })
+
+ describe('()', () => {
+ it('creates a new object of type Circle', () => {
+ expect(new Circle()).toEqual(any(Circle))
+ })
+
+ it('sets passed attributes on the element', () => {
+ expect(new Circle({ id: 'foo' }).id()).toBe('foo')
+ })
+ })
+
+ describe('radius()', () => {
+ it('calls attr with r', () => {
+ const spy = spyOn(circle, 'attr').and.callThrough()
+ circle.radius(123)
+ expect(spy).toHaveBeenCalledWith('r', 123)
+ })
+ })
+
+ describe('rx()', () => {
+ it('calls attr with r', () => {
+ const spy = spyOn(circle, 'attr')
+ circle.rx(123)
+ expect(spy).toHaveBeenCalledWith('r', 123)
+ })
+ })
+
+ describe('ry()', () => {
+ it('calls rx', () => {
+ const spy = spyOn(circle, 'rx')
+ circle.ry(123)
+ expect(spy).toHaveBeenCalledWith(123)
+ })
+ })
+
+ describe('size()', () => {
+ it('calls radius with half of the size', () => {
+ const spy = spyOn(circle, 'radius')
+ circle.size(100)
+ expect(spy).toHaveBeenCalledWith(objectContaining({ value: 50 }))
+ })
+ })
+
+ describe('Container', () => {
+ describe('circle()', () => {
+ it('creates a circle with given size', () => {
+ const group = new G()
+ const circle = group.circle(50)
+ expect(circle.attr('r')).toBe(25)
+ expect(circle).toEqual(any(Circle))
+ })
+ })
+ })
+})
diff --git a/src/main.js b/src/main.js
index 12ebc7b..a8da19f 100644
--- a/src/main.js
+++ b/src/main.js
@@ -10,7 +10,6 @@ import './modules/optional/transform.js'
import { extend, makeInstance } from './utils/adopter.js'
import { getMethodNames, getMethodsFor } from './utils/methods.js'
import Box from './types/Box.js'
-import Circle from './elements/Circle.js'
import Color from './types/Color.js'
import Container from './elements/Container.js'
import Defs from './elements/Defs.js'
@@ -148,8 +147,8 @@ extend([
extend([
Rect,
Ellipse,
- Circle,
- Gradient
+ Gradient,
+ Runner
], getMethodsFor('radius'))
extend(EventTarget, getMethodsFor('EventTarget'))
diff --git a/src/modules/optional/sugar.js b/src/modules/optional/sugar.js
index 0de2c04..72c02ca 100644
--- a/src/modules/optional/sugar.js
+++ b/src/modules/optional/sugar.js
@@ -104,11 +104,11 @@ registerMethods([ 'Element', 'Runner' ], {
registerMethods('radius', {
// Add x and y radius
- radius: function (x, y) {
+ radius: function (x, y = x) {
var type = (this._element || this).type
return type === 'radialGradient' || type === 'radialGradient'
? this.attr('r', new SVGNumber(x))
- : this.rx(x).ry(y == null ? x : y)
+ : this.rx(x).ry(y)
}
})