Skip to content

Commit

Permalink
added foreignObject to the core
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuzzyma committed Feb 18, 2019
1 parent a118f5e commit 9e75004
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ The document follows the conventions described in [“Keep a CHANGELOG”](http:

====

## [3.0.12]

### Fixed
- fixed package.json which points to correct file for webpack now (browser keyword)
- fixed typescript types

### Added
- added `ForeignObject` to the core

## [3.0.11] - 2019-01-22

### Fixed
Expand Down
47 changes: 47 additions & 0 deletions spec/spec/elements/ForeignObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { makeInstance, ForeignObject } from '../../../src/main.js';

const { any, createSpy, objectContaining } = jasmine


describe('ForeignObject.js', () => {

describe('()', () => {
it('creates a new object of type ForeignObject', () => {
expect(new ForeignObject()).toEqual(any(ForeignObject))
})

it('sets passed attributes on the element', () => {
expect(new ForeignObject({id:'foo'}).id()).toBe('foo')
})
})

describe('Container', () => {
describe('foreignObject()', () => {
it('creates a foreignObject in the container', () => {
const canvas = makeInstance().addTo('#canvas')
const foreignObject = canvas.foreignObject()
expect(foreignObject).toEqual(any(ForeignObject))
expect(foreignObject.parent()).toBe(canvas)
})

it('sets width and height correctly on construction', () => {
const canvas = makeInstance().addTo('#canvas')
const foreignObject = canvas.foreignObject(100, 200)
expect(foreignObject.width()).toBe(100)
expect(foreignObject.height()).toBe(200)
})
})
})

describe('Element methods', () => {
it('is usable with Elements methods such as height() and width()', () => {
const canvas = makeInstance().addTo('#canvas')
const foreignObject = canvas.foreignObject()
foreignObject.width(100).height(200).x(10).y(20)
expect(foreignObject.width()).toBe(100)
expect(foreignObject.height()).toBe(200)
expect(foreignObject.x()).toBe(10)
expect(foreignObject.y()).toBe(20)
})
})
})
2 changes: 1 addition & 1 deletion src/elements/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class Circle extends Shape {
extend(Circle, { x, y, cx, cy, width, height })

registerMethods({
Element: {
Container: {
// Create circle element
circle: wrapWithAttrCheck(function (size) {
return this.put(new Circle())
Expand Down
19 changes: 19 additions & 0 deletions src/elements/ForeignObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
import { registerMethods } from '../utils/methods.js'
import Element from './Element.js'

export default class ForeignObject extends Element {
constructor (node) {
super(nodeOrNew('foreignObject', node), node)
}
}

registerMethods({
Container: {
foreignObject: wrapWithAttrCheck(function (width, height) {
return this.put(new ForeignObject()).size(width, height)
})
}
})

register(ForeignObject)
2 changes: 1 addition & 1 deletion src/elements/G.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default class G extends Container {
}

registerMethods({
Element: {
Container: {
// Create a group element
group: wrapWithAttrCheck(function () {
return this.put(new G())
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export { default as Defs } from './elements/Defs.js'
export { default as Dom } from './elements/Dom.js'
export { default as Element } from './elements/Element.js'
export { default as Ellipse } from './elements/Ellipse.js'
export { default as ForeignObject } from './elements/ForeignObject.js'
export { default as Gradient } from './elements/Gradient.js'
export { default as G } from './elements/G.js'
export { default as A } from './elements/A.js'
Expand Down

0 comments on commit 9e75004

Please sign in to comment.