resolveGraphData produces the renderable data for the chosen source.
(cfg graphViewArgs)
| 426 | |
| 427 | // resolveGraphData produces the renderable data for the chosen source. |
| 428 | func resolveGraphData(cfg graphViewArgs) (GraphData, error) { |
| 429 | switch cfg.Source { |
| 430 | case "knowledge", "conversation": |
| 431 | prov := currentGraphSourceProvider() |
| 432 | if prov == nil { |
| 433 | return GraphData{}, fmt.Errorf("source %q is unavailable here; pass nodes/edges with source=json instead", cfg.Source) |
| 434 | } |
| 435 | var ( |
| 436 | data GraphData |
| 437 | err error |
| 438 | ) |
| 439 | if cfg.Source == "knowledge" { |
| 440 | data, err = prov.KnowledgeGraph() |
| 441 | } else { |
| 442 | data, err = prov.ConversationGraph() |
| 443 | } |
| 444 | if err != nil { |
| 445 | return GraphData{}, err |
| 446 | } |
| 447 | applyGraphMeta(&data, cfg) |
| 448 | return sanitizeGraphData(data), nil |
| 449 | default: // json |
| 450 | data := GraphData{Nodes: cfg.Nodes, Edges: cfg.Edges} |
| 451 | if cfg.File != "" { |
| 452 | fileData, err := readGraphDataFile(cfg.File) |
| 453 | if err != nil { |
| 454 | return GraphData{}, err |
| 455 | } |
| 456 | data.Nodes = append(data.Nodes, fileData.Nodes...) |
| 457 | data.Edges = append(data.Edges, fileData.Edges...) |
| 458 | } |
| 459 | applyGraphMeta(&data, cfg) |
| 460 | return sanitizeGraphData(data), nil |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | func applyGraphMeta(data *GraphData, cfg graphViewArgs) { |
| 465 | if cfg.Title != "" { |