-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
276 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
attr as svgAttr, | ||
create as svgCreate | ||
} from 'tiny-svg'; | ||
|
||
import { Element } from '../../model/Types'; | ||
|
||
import OutlineProvider, { Outline } from './OutlineProvider'; | ||
|
||
export class FooOutlineProvider implements OutlineProvider { | ||
getOutline(element: Element): Outline { | ||
const outline = svgCreate('circle'); | ||
|
||
svgAttr(outline, { | ||
cx: element.width / 2, | ||
cy: element.height / 2, | ||
r: 23 | ||
}); | ||
|
||
return outline; | ||
} | ||
|
||
updateOutline(element: Element, outline: Outline): boolean { | ||
if (element.type === 'Foo') { | ||
svgAttr(outline, { | ||
cx: element.width / 2, | ||
cy: element.height / 2, | ||
r: 23 | ||
}); | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Element } from '../../model/Types'; | ||
|
||
export type Outline = SVGSVGElement | SVGCircleElement | SVGRectElement; | ||
|
||
/** | ||
* An interface to be implemented by an outline provider. | ||
*/ | ||
export default interface OutlineProvider { | ||
|
||
/** | ||
* Returns outline shape for given element. | ||
* | ||
* @example | ||
* | ||
* ```javascript | ||
* getOutline(element) { | ||
* if (element.type === 'Foo') { | ||
* const outline = svgCreate('circle'); | ||
* | ||
* svgAttr(outline, { | ||
* cx: element.width / 2, | ||
* cy: element.height / 2, | ||
* r: 23 | ||
* }); | ||
* | ||
* return outline; | ||
* } | ||
* } | ||
* ``` | ||
* | ||
* @param element | ||
*/ | ||
getOutline: (element: Element) => Outline; | ||
|
||
/** | ||
* Updates outline shape based on element's current size. Returns true if | ||
* update was handled by provider. | ||
* | ||
* @example | ||
* | ||
* ```javascript | ||
* updateOutline(element, outline) { | ||
* if (element.type === 'Foo') { | ||
* svgAttr(outline, { | ||
* cx: element.width / 2, | ||
* cy: element.height / 2, | ||
* r: 23 | ||
* }); | ||
* } else if (element.type === 'Bar') { | ||
* return true; | ||
* } | ||
* | ||
* return false; | ||
* } | ||
* ``` | ||
* | ||
* @param element | ||
* @param outline | ||
*/ | ||
updateOutline: (element: Element, outline: Outline) => boolean; | ||
} |
Oops, something went wrong.