6
6
import assert from 'assert' ;
7
7
8
8
import { type BlockDefinition } from '@jvalue/jayvee-language-server' ;
9
+ import { stringify } from 'yaml' ;
9
10
10
11
import { type ExecutionContext } from '../execution-context' ;
11
12
@@ -119,26 +120,76 @@ export class ClassAssignment {
119
120
}
120
121
}
121
122
123
+ export interface ThemeVariables {
124
+ darkMode : boolean ;
125
+ background : string ;
126
+ fontFamily : string ;
127
+ fontSize : string ;
128
+ primaryColor : string ;
129
+ primaryTextColor : string ;
130
+ primaryBorderColor : string ;
131
+ secondaryColor : string ;
132
+ secondaryTextColor : string ;
133
+ secondaryBorderColor : string ;
134
+ tertiaryColor : string ;
135
+ tertiaryTextColor : string ;
136
+ tertiaryBorderColor : string ;
137
+ noteBkgColor : string ;
138
+ noteTextColor : string ;
139
+ noteBorderColor : string ;
140
+ lineColor : string ;
141
+ textColor : string ;
142
+ mainBkg : string ;
143
+ errorBkgColor : string ;
144
+ errorTextColor : string ;
145
+
146
+ nodeBorder : string ;
147
+ clusterBkg : string ;
148
+ clusterBorder : string ;
149
+ defaultLinkColor : string ;
150
+ titleColor : string ;
151
+ edgeLabelBackground : string ;
152
+ nodeTextColor : string ;
153
+ }
154
+
155
+ export interface ElkLayoutConfig {
156
+ mergeEdges : boolean ;
157
+ nodePlacementStrategy :
158
+ | 'BRANDES_KOEPF'
159
+ | 'SIMPLE'
160
+ | 'NETWORK_SIMPLEX'
161
+ | 'LINEAR_SEGMENTS' ;
162
+ }
163
+
164
+ export interface GraphConfiguration {
165
+ look : 'classic' | 'handDrawn' ;
166
+ theme : 'default' | 'neutral' | 'dark' | 'forest' | 'plain' ;
167
+ themeVariables : Partial < ThemeVariables > ;
168
+ layout : 'dagre' | 'elk' ;
169
+ elk : Partial < ElkLayoutConfig > ;
170
+ }
171
+
122
172
export type GraphDirection = 'TB' | 'BT' | 'RL' | 'LR' ;
173
+
123
174
export class Graph {
124
175
private readonly _id : Id = getId ( ) ;
125
176
private direction : GraphDirection = 'TB' ;
126
177
private nodes = new Map < Id , Node > ( ) ;
127
178
128
179
private edges = new Map < Id , Edge > ( ) ;
129
- private edgeAttributes : { id : Id ; attributes : string [ ] } [ ] = [ ] ;
180
+ private edgeAttributes : EdgeAttribute [ ] = [ ] ;
130
181
131
182
private subgraphs = new Map < Id , Graph > ( ) ;
132
183
133
- private classDefinitions : {
134
- class : string ;
135
- propertiesAndValues : string [ ] ;
136
- } [ ] = [ ] ;
137
- private classAssignments : { id : Id ; class : string } [ ] = [ ] ;
184
+ private classDefinitions : ClassDefinition [ ] = [ ] ;
185
+ private classAssignments : ClassAssignment [ ] = [ ] ;
138
186
139
187
private blocks = new Map < BlockDefinition , Id > ( ) ;
140
188
141
- constructor ( public title ?: string ) { }
189
+ constructor (
190
+ public title ?: string ,
191
+ public configuration ?: Partial < GraphConfiguration > ,
192
+ ) { }
142
193
143
194
get id ( ) : Id {
144
195
return this . _id ;
@@ -188,6 +239,14 @@ export class Graph {
188
239
this . edges . set ( edge . id , edge ) ;
189
240
}
190
241
242
+ public addClassAssignment ( assignment : ClassAssignment ) {
243
+ this . classAssignments . push ( assignment ) ;
244
+ }
245
+
246
+ public addClassDefinition ( classDefinition : ClassDefinition ) {
247
+ this . classDefinitions . push ( classDefinition ) ;
248
+ }
249
+
191
250
public toSubgraph ( indents : number ) : string {
192
251
const title = this . title !== undefined ? ` [${ this . title } ]` : '' ;
193
252
return `subgraph ${ this . id } ${ title }
@@ -197,9 +256,15 @@ ${indents > 0 ? '\t'.repeat(indents - 1) : ''}end`;
197
256
}
198
257
199
258
toString ( ) : string {
200
- const title = this . title !== undefined ? `\ntitle: ${ this . title } ` : '' ;
201
- return `---${ title }
202
- ---
259
+ return `---
260
+ ${
261
+ this . title !== undefined || this . configuration !== undefined
262
+ ? stringify ( {
263
+ title : this . title ,
264
+ config : this . configuration ,
265
+ } )
266
+ : '\n'
267
+ } ---
203
268
flowchart ${ this . direction }
204
269
${ this . content ( 1 ) } `;
205
270
}
0 commit comments