Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support for extensibility #193

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ This is how the Decorator pattern can look in nomnoml syntax:
[<hidden> name]
[<table> name| a | 5 || b | 7]

### Add new types
```javascript
const component = {
name: 'newTypeComponentName',
layout: function (config, clas) {
},
visualizer: function (node, x, y, config, g) {
}
}
nomnoml.registerComponent(component);
```
#### Example how to use new type
[<actor>Actor] --> [<newTypeComponentName>Component]

### Directives

#import: my-common-styles.nomnoml
Expand Down
1 change: 1 addition & 0 deletions src/GraphicsSvg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export function GraphicsSvg(document?: HTMLDocument): ISvgGraphics {
{
x,
y,
fill: current.attr.fill,
stroke: 'none',
font: undefined as undefined | string,
style: undefined as undefined | string,
Expand Down
23 changes: 22 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { styles, visualizers, layouters, buildStyle } from './visuals'
import { NodeLayouter, Visual, Visualizer } from "./domain";
export {
draw,
renderSvg,
Expand All @@ -11,4 +13,23 @@ export var version = '1.5.3'
export * as skanaar from './util'
export { parse } from './parser'
export { layout } from './layouter'
export { styles, visualizers } from './visuals'
export { styles, visualizers }
export type Component = {
name: Visual,
layout: NodeLayouter,
visualizer: Visualizer
}
export function registerComponent(component: Component) {
const name = String(component.name);
Object.assign(layouters, { [name]: component.layout } );
Object.assign(visualizers, { [name]: component.visualizer } );
Object.assign(
styles,
{
[name]: buildStyle({ visual: component.name },
{ center:true },
{ center: true }
)
}
);
}