Stable categorical colors with contrast against the HTML graph's dark canvas. Exhaustive matching keeps ontology additions from silently sharing a fallback.
(kind: &str)
| 638 | /// Stable categorical colors with contrast against the HTML graph's dark canvas. |
| 639 | /// Exhaustive matching keeps ontology additions from silently sharing a fallback. |
| 640 | fn html_node_color(kind: &str) -> String { |
| 641 | let Some(class) = Class::from_iri(kind) else { |
| 642 | // Unlike a palette indexed by the types currently visible, hashing the |
| 643 | // full IRI keeps an external type's color stable between exports. |
| 644 | let hash = kind.bytes().fold(2166136261u32, |hash, byte| { |
| 645 | (hash ^ u32::from(byte)).wrapping_mul(16777619) |
| 646 | }); |
| 647 | return format!("hsl({}, 65%, 68%)", hash % 360); |
| 648 | }; |
| 649 | match class { |
| 650 | Class::WorkIntent => "#63d5ea", |
| 651 | Class::FeatureIntent => "#56cfe1", |
| 652 | Class::BugIntent => "#ff8a9a", |
| 653 | Class::ReviewIntent => "#a5b4fc", |
| 654 | Class::ManagedIntent => "#8be4f0", |
| 655 | Class::Goal => "#6ed4ae", |
| 656 | Class::Memory => "#e2bc81", |
| 657 | Class::Skill => "#a4d98b", |
| 658 | Class::ToolResult => "#8da9bd", |
| 659 | Class::Task => "#dd81ef", |
| 660 | Class::AcceptanceCriterion => "#c6e96e", |
| 661 | Class::ScopeItem => "#c5a582", |
| 662 | Class::Constraint => "#f59ac2", |
| 663 | Class::Todo => "#d79e64", |
| 664 | Class::Session => "#b6a4ff", |
| 665 | Class::SessionTurn => "#39b8bd", |
| 666 | Class::ManagedTurn => "#8ad4dc", |
| 667 | Class::ProvenanceGraph => "#72a7ff", |
| 668 | Class::Attestation => "#f0c4ec", |
| 669 | Class::Finding => "#ffad66", |
| 670 | Class::Change => "#ff786f", |
| 671 | Class::View => "#9878e8", |
| 672 | Class::File => "#53d89b", |
| 673 | Class::Identity => "#f4d06f", |
| 674 | Class::Concept => "#aac4a0", |
| 675 | Class::Project => "#adcbe7", |
| 676 | Class::ProjectIdentity => "#bba2a0", |
| 677 | Class::VerificationStatus => "#d4d8e3", |
| 678 | } |
| 679 | .to_owned() |
| 680 | } |
| 681 | |
| 682 | /// Generate a self-contained HTML page with a D3.js force-directed graph. |
| 683 | pub(crate) fn emit_html(query: &str, nodes: &[KgNode], edges: &[KgEdge]) -> String { |