packages/ast-to-mmd/src/app/graph-blocks/switch-declaration.graph-block.ts
Properties |
|
Methods |
|
Accessors |
constructor(id: string, blockCases: CaseDeclarationGraphBlock[], condition: string, defaultClauseExists: boolean)
|
Private _lazyDependencies |
Type : string[]
|
Default value : []
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:30
|
Lazy dependencies ready to render when this node is rendered. |
Private _parent |
Type : GraphBlock | undefined
|
Default value : undefined
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:25
|
Parent of current node in graph. Can be undefined. |
Private _parentSiblingCondition |
Type : SiblingCondition
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:39
|
SiblingCondition for finding correct parent. |
Private _siblingCondition |
Type : SiblingCondition
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:35
|
Private Static Readonly EMPTY_LINE_RENDERER_MODIFIER |
Type : LineRendererModifier
|
Default value : () => {...}
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:20
|
Empty implementation of LineRendererModifier. |
Public Readonly id |
Type : string
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:46
|
Unique ID in the node graph.
|
Private Static Readonly POSITIVE_SIBLING_CONDITION |
Type : SiblingCondition
|
Default value : new PositiveSiblingCondition()
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:16
|
Positive sibling condition default for all GraphBlock. |
Private Static Readonly SHAPE_RENDERER |
Type : ShapeRenderer
|
Default value : new ShapeRenderer()
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:12
|
Shape renderer for generating different shapes in graph. |
Private __buildLineModifier | ||||||
__buildLineModifier(child: CaseDeclarationGraphBlock)
|
||||||
Parameters :
Returns :
LineRendererModifier
|
Public render | ||||||
render(_indent: number)
|
||||||
Inherited from
GraphBlock
|
||||||
Defined in
GraphBlock:26
|
||||||
Parameters :
Returns :
string
|
Protected renderDirectDependencies | ||||||
renderDirectDependencies(_indent: number)
|
||||||
Parameters :
Returns :
string
|
Protected createLineBuilder |
createLineBuilder(lhsId: string, rhsId: string)
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:71
|
Returns :
LineRenderer
|
Protected renderChildren | |||||||||
renderChildren(indent: number, children: GraphBlock[])
|
|||||||||
Inherited from
BlockDeclarationGraphBlock
|
|||||||||
Defined in
BlockDeclarationGraphBlock:64
|
|||||||||
Parameters :
Returns :
string
|
Protected renderDependencies | ||||||
renderDependencies(_indent: number)
|
||||||
Inherited from
BlockDeclarationGraphBlock
|
||||||
Defined in
BlockDeclarationGraphBlock:60
|
||||||
Parameters :
Returns :
string
|
Private __multiFindChildIndex | ||||||||||||
__multiFindChildIndex(children: GraphBlock[][], child: GraphBlock)
|
||||||||||||
Inherited from
GraphBlock
|
||||||||||||
Defined in
GraphBlock:575
|
||||||||||||
Private method for finding a child index of defined block in a multidimensional array of children.
Parameters :
Returns :
| undefined
Coordinates of child block or undefined when block is not found. |
Private __renderLines | ||||||||||||||||||||||||
__renderLines(indent: number, id: string, ids: string[], direction: "left" | "right", builderModifier: LineRendererModifier[])
|
||||||||||||||||||||||||
Inherited from
GraphBlock
|
||||||||||||||||||||||||
Defined in
GraphBlock:546
|
||||||||||||||||||||||||
Private method for rendering lines between nodes in defined directions.
Parameters :
Returns :
string
Rendered line. |
Protected _assignParent | ||||||||
_assignParent(children: GraphBlock[])
|
||||||||
Inherited from
GraphBlock
|
||||||||
Defined in
GraphBlock:289
|
||||||||
Helper method for assigning this parent into each children.
Parameters :
Returns :
void
|
Protected _filterChildren | ||||||||
_filterChildren(children: GraphBlock[])
|
||||||||
Inherited from
GraphBlock
|
||||||||
Defined in
GraphBlock:466
|
||||||||
Helper method for filtering array of children.
Parameters :
Returns :
GraphBlock[]
|
Protected _findParentBySiblingCondition | ||||||||||||
_findParentBySiblingCondition(child: GraphBlock, siblingCondition: SiblingCondition)
|
||||||||||||
Inherited from
GraphBlock
|
||||||||||||
Defined in
GraphBlock:521
|
||||||||||||
Helper method for finding an indirect parent of defined child by SiblingCondition.
Parameters :
Returns :
GraphBlock | undefined
|
Protected _findSiblingChild | ||||||||||||||||||||
_findSiblingChild(child: GraphBlock, parentSiblingCondition: SiblingCondition, siblingCondition: SiblingCondition)
|
||||||||||||||||||||
Inherited from
GraphBlock
|
||||||||||||||||||||
Defined in
GraphBlock:478
|
||||||||||||||||||||
Helper method for finding a sibling of defined child in parents children.
Parameters :
Returns :
GraphBlock | undefined
|
Protected _generateSpace | ||||||||
_generateSpace(count: number)
|
||||||||
Inherited from
GraphBlock
|
||||||||
Defined in
GraphBlock:301
|
||||||||
Helper method for generating space.
Parameters :
Returns :
string
Space of defined length. |
Protected _multiFilterChildren | ||||||||
_multiFilterChildren(children: GraphBlock[][])
|
||||||||
Inherited from
GraphBlock
|
||||||||
Defined in
GraphBlock:456
|
||||||||
Helper method for filtering children in multidimensional array of children.
Parameters :
Returns :
[][]
|
Protected _renderConnectionWithParent | |||||||||||||||
_renderConnectionWithParent(indent: number, children: GraphBlock, lastIds: string[], priorityBuilderModifier: LineRendererModifier[])
|
|||||||||||||||
Inherited from
GraphBlock
|
|||||||||||||||
Defined in
GraphBlock:410
|
|||||||||||||||
Parameters :
Returns :
string
|
Protected _renderDependencies | ||||||||||||
_renderDependencies(indent: number, blocks: GraphBlock[])
|
||||||||||||
Inherited from
GraphBlock
|
||||||||||||
Defined in
GraphBlock:346
|
||||||||||||
Helper method for rendering dependencies with defined indent between blocks.
Parameters :
Returns :
string
Dependencies of blocks. |
Protected _renderLine | ||||||||||||||||||||
_renderLine(indent: number, lhsId: string, rhsId: string, builderModifier: LineRendererModifier[])
|
||||||||||||||||||||
Inherited from
GraphBlock
|
||||||||||||||||||||
Defined in
GraphBlock:314
|
||||||||||||||||||||
Helper method for generating line between two nodes.
Parameters :
Returns :
string
Line definition between two nodes. |
Protected _renderLinesL2R | ||||||||||||||||||||
_renderLinesL2R(indent: number, toId: string, fromIds: string[], builderModifier: LineRendererModifier[])
|
||||||||||||||||||||
Inherited from
GraphBlock
|
||||||||||||||||||||
Defined in
GraphBlock:383
|
||||||||||||||||||||
Helper method for rendering line starting in one node and ending in multiple nodes.
Parameters :
Returns :
string
Rendered line. |
Protected _renderLinesR2L | ||||||||||||||||||||
_renderLinesR2L(indent: number, fromId: string, toIds: string[], builderModifier: LineRendererModifier[])
|
||||||||||||||||||||
Inherited from
GraphBlock
|
||||||||||||||||||||
Defined in
GraphBlock:401
|
||||||||||||||||||||
Helper method for rendering line starting in multiple nodes and ending in one node.
Parameters :
Returns :
string
Rendered line. |
Protected _renderShape | ||||||||||||
_renderShape(text: string, shape: Shape)
|
||||||||||||
Inherited from
GraphBlock
|
||||||||||||
Defined in
GraphBlock:335
|
||||||||||||
Helper method for rendering defined shape with text.
Parameters :
Returns :
string
Rendered shape with text. |
Protected renderInSubgraph | ||||||||||||||||||||||||||||||
renderInSubgraph(_indent: number, id: string, text: string, bodyRenderer: (indent: number) => void, direction: "TB" | "TD" | "BT" | "LR" | "RL")
|
||||||||||||||||||||||||||||||
Inherited from
GraphBlock
|
||||||||||||||||||||||||||||||
Defined in
GraphBlock:86
|
||||||||||||||||||||||||||||||
Renders current node wrapped in a subgraph. Direction options:
Parameters :
Returns :
string
Graph wrapped in a subgraph. |
Public renderLazyDependencies | ||||||||
renderLazyDependencies(_indent: number)
|
||||||||
Inherited from
GraphBlock
|
||||||||
Defined in
GraphBlock:63
|
||||||||
Renders lazy dependencies of current node.
Parameters :
Returns :
string
|
Public toString |
toString()
|
Inherited from
GraphBlock
|
Defined in
GraphBlock:589
|
Returns :
string
|
blockKind |
getblockKind()
|
firstBlock |
getfirstBlock()
|
lastBlocks |
getlastBlocks()
|
import { BlockKind } from '../block.kind';
import { BlockDeclarationGraphBlock } from './block-declaration.graph-block';
import { CaseDeclarationGraphBlock } from './case-declaration.graph-block';
import { GraphBlock } from './graph-block';
import { LineRendererModifier, Shape } from './renderer';
export class SwitchDeclarationGraphBlock extends BlockDeclarationGraphBlock {
constructor(id: string, blockCases: CaseDeclarationGraphBlock[], private readonly condition: string, private readonly defaultClauseExists: boolean) {
super(id, blockCases);
}
public override get blockKind(): BlockKind {
return BlockKind.SWITCH_DECLARATION;
}
override get firstBlock(): GraphBlock {
return this;
}
public override get lastBlocks(): string[] {
return this.childBlocks.map(child => child.lastBlocks).reduce((prev: string[], curr: string[]) => [...prev, ...curr], [])
}
public override render(_indent: number): string {
return `
${this._generateSpace(_indent + 1)}${this.id}${this._renderShape(`SWITCH <br> ${this.condition}`, Shape.RHOMBUS)}
${super.render(_indent)}
${this.renderDirectDependencies(_indent + 1)}
`;
}
protected renderDirectDependencies(_indent: number): string {
const directDependencies = this.childBlocks.map(child =>
this._renderLine(_indent, this.id, child.firstBlock.id, this.__buildLineModifier(child as CaseDeclarationGraphBlock))
).join('\n');
if (!this.defaultClauseExists) {
const sibling: GraphBlock | undefined = this._findSiblingChild(this);
if (sibling) {
this.lazyDependency = this._renderLine(0, this.id, sibling.id, builder => builder.setConnectionDescription('default'))
}
}
return directDependencies;
}
private __buildLineModifier(child: CaseDeclarationGraphBlock): LineRendererModifier {
return builder => builder.setConnectionDescription(child.condition);
}
}
export type CaseMap = { condition: string, block: GraphBlock };