ZahirJS commited on
Commit
2eb272a
·
verified ·
1 Parent(s): dfe2cff

Update entity_relationship_generator.py

Browse files
Files changed (1) hide show
  1. entity_relationship_generator.py +28 -40
entity_relationship_generator.py CHANGED
@@ -214,22 +214,7 @@ def generate_entity_relationship_diagram(json_input: str, output_format: str) ->
214
  'bgcolor': 'white',
215
  'pad': '0.5',
216
  'nodesep': '1.2',
217
- 'ranksep': '1.8',
218
- 'fontname': 'Arial',
219
- 'dpi': '300',
220
- 'overlap': 'false'
221
- },
222
- node_attr={
223
- 'fontname': 'Arial',
224
- 'fontsize': '10',
225
- 'color': 'black',
226
- 'penwidth': '1.5'
227
- },
228
- edge_attr={
229
- 'fontname': 'Arial',
230
- 'fontsize': '9',
231
- 'color': 'black',
232
- 'penwidth': '1'
233
  }
234
  )
235
 
@@ -244,14 +229,10 @@ def generate_entity_relationship_diagram(json_input: str, output_format: str) ->
244
  if not entity_name:
245
  raise ValueError(f"Invalid entity: {entity}")
246
 
247
- entity_label = f"{entity_name}"
248
 
249
  if attributes:
250
- entity_label += "|"
251
- primary_keys = []
252
- foreign_keys = []
253
- regular_attrs = []
254
-
255
  for attr in attributes:
256
  attr_name = attr.get('name', '')
257
  attr_type = attr.get('type', 'regular')
@@ -261,11 +242,11 @@ def generate_entity_relationship_diagram(json_input: str, output_format: str) ->
261
 
262
  if attr_type == 'primary_key':
263
  if is_multivalued:
264
- primary_keys.append(f"PK: {{ {attr_name} }}")
265
  else:
266
- primary_keys.append(f"PK: {attr_name}")
267
  elif attr_type == 'foreign_key':
268
- foreign_keys.append(f"FK: {attr_name}")
269
  else:
270
  attr_display = attr_name
271
  if is_derived:
@@ -274,21 +255,27 @@ def generate_entity_relationship_diagram(json_input: str, output_format: str) ->
274
  attr_display = f"{{ {attr_display} }}"
275
  if is_composite:
276
  attr_display = f"( {attr_display} )"
277
- regular_attrs.append(attr_display)
 
 
 
278
 
279
- all_attrs = primary_keys + foreign_keys + regular_attrs
280
- entity_label += "\\l".join(all_attrs) + "\\l"
 
 
 
281
 
282
  if entity_type == 'weak':
283
  shape = 'record'
284
  style = 'filled'
285
- fillcolor = '#f0f0f0'
286
- penwidth = '3'
287
  else:
288
  shape = 'record'
289
  style = 'filled'
290
- fillcolor = 'white'
291
- penwidth = '1.5'
292
 
293
  dot.node(
294
  entity_name,
@@ -296,6 +283,7 @@ def generate_entity_relationship_diagram(json_input: str, output_format: str) ->
296
  shape=shape,
297
  style=style,
298
  fillcolor=fillcolor,
 
299
  penwidth=penwidth
300
  )
301
 
@@ -311,18 +299,18 @@ def generate_entity_relationship_diagram(json_input: str, output_format: str) ->
311
  if rel_type == 'identifying':
312
  rel_shape = 'diamond'
313
  rel_style = 'filled'
314
- rel_color = '#d0d0d0'
315
- rel_penwidth = '3'
316
  elif rel_type == 'weak':
317
  rel_shape = 'diamond'
318
  rel_style = 'filled'
319
- rel_color = '#e8e8e8'
320
- rel_penwidth = '2'
321
  else:
322
  rel_shape = 'diamond'
323
  rel_style = 'filled'
324
- rel_color = '#d0d0d0'
325
- rel_penwidth = '1.5'
326
 
327
  dot.node(
328
  rel_name,
@@ -330,6 +318,7 @@ def generate_entity_relationship_diagram(json_input: str, output_format: str) ->
330
  shape=rel_shape,
331
  style=rel_style,
332
  fillcolor=rel_color,
 
333
  fontcolor='black',
334
  penwidth=rel_penwidth
335
  )
@@ -341,8 +330,7 @@ def generate_entity_relationship_diagram(json_input: str, output_format: str) ->
341
  entity,
342
  rel_name,
343
  label=cardinality,
344
- labelfontsize='10',
345
- labelfontcolor='black'
346
  )
347
 
348
  with NamedTemporaryFile(delete=False, suffix=f'.{output_format}') as tmp:
 
214
  'bgcolor': 'white',
215
  'pad': '0.5',
216
  'nodesep': '1.2',
217
+ 'ranksep': '1.8'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  }
219
  )
220
 
 
229
  if not entity_name:
230
  raise ValueError(f"Invalid entity: {entity}")
231
 
232
+ entity_parts = [entity_name]
233
 
234
  if attributes:
235
+ attr_section = ""
 
 
 
 
236
  for attr in attributes:
237
  attr_name = attr.get('name', '')
238
  attr_type = attr.get('type', 'regular')
 
242
 
243
  if attr_type == 'primary_key':
244
  if is_multivalued:
245
+ attr_display = f"PK: {{ {attr_name} }}"
246
  else:
247
+ attr_display = f"PK: {attr_name}"
248
  elif attr_type == 'foreign_key':
249
+ attr_display = f"FK: {attr_name}"
250
  else:
251
  attr_display = attr_name
252
  if is_derived:
 
255
  attr_display = f"{{ {attr_display} }}"
256
  if is_composite:
257
  attr_display = f"( {attr_display} )"
258
+
259
+ if attr_section:
260
+ attr_section += "\\l"
261
+ attr_section += attr_display
262
 
263
+ if attr_section:
264
+ attr_section += "\\l"
265
+ entity_parts.append(attr_section)
266
+
267
+ entity_label = "|".join(entity_parts)
268
 
269
  if entity_type == 'weak':
270
  shape = 'record'
271
  style = 'filled'
272
+ fillcolor = '#e8e8e8'
273
+ penwidth = '2'
274
  else:
275
  shape = 'record'
276
  style = 'filled'
277
+ fillcolor = '#d0d0d0'
278
+ penwidth = '1'
279
 
280
  dot.node(
281
  entity_name,
 
283
  shape=shape,
284
  style=style,
285
  fillcolor=fillcolor,
286
+ color='black',
287
  penwidth=penwidth
288
  )
289
 
 
299
  if rel_type == 'identifying':
300
  rel_shape = 'diamond'
301
  rel_style = 'filled'
302
+ rel_color = '#c0c0c0'
303
+ rel_penwidth = '2'
304
  elif rel_type == 'weak':
305
  rel_shape = 'diamond'
306
  rel_style = 'filled'
307
+ rel_color = '#e0e0e0'
308
+ rel_penwidth = '1'
309
  else:
310
  rel_shape = 'diamond'
311
  rel_style = 'filled'
312
+ rel_color = '#c0c0c0'
313
+ rel_penwidth = '1'
314
 
315
  dot.node(
316
  rel_name,
 
318
  shape=rel_shape,
319
  style=rel_style,
320
  fillcolor=rel_color,
321
+ color='black',
322
  fontcolor='black',
323
  penwidth=rel_penwidth
324
  )
 
330
  entity,
331
  rel_name,
332
  label=cardinality,
333
+ color='black'
 
334
  )
335
 
336
  with NamedTemporaryFile(delete=False, suffix=f'.{output_format}') as tmp: