Class: OKF::Server::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/okf/server/graph.rb

Overview

Renders an OKF::Bundle::Graph as the interactive graph page served by OKF::Server::App. The markup lives in graph/template.html.erb; #render returns the HTML string.

The page boots from a minimal payload — nodes carry only id + title, plus compact TYPES/TAGS inverted indexes for colouring and filtering — and pulls each concept's markdown body (and metadata) from the server on demand via fetch, rendering it client-side with marked. Node bodies are therefore NOT embedded here.

NOTE (trust boundary): the page loads Cytoscape + marked from a CDN and renders concept markdown without sanitization, so only serve bundles you trust. The inline--escaped by #json_for_script (stdlib ERB does not auto-escape).

Constant Summary collapse

TEMPLATE =
File.expand_path("graph/template.html.erb", __dir__)
LAYOUTS =
%w[cose concentric breadthfirst circle grid].freeze
MIN_SIZE =

Node-diameter range in px; the template scales within it by node degree.

14
MAX_SIZE =
44
LT_ESCAPE =

The 6-character JSON unicode escape for < (backslash, u, 0, 0, 3, c), built from the backslash code point so no literal escape appears here.

(92.chr(Encoding::UTF_8) + "u003c").freeze

Instance Method Summary collapse

Constructor Details

#initialize(graph, title: nil, link: nil, layout: "cose", node_endpoint: "node", meta_endpoint: "node/meta") ⇒ Graph

+node_endpoint+/+meta_endpoint+ are the (mount-relative) URLs the page fetches a concept's raw markdown and metadata fragment from — relative so the page works whether served at "/" or mounted under a Rails prefix.



34
35
36
37
38
39
40
41
# File 'lib/okf/server/graph.rb', line 34

def initialize(graph, title: nil, link: nil, layout: "cose", node_endpoint: "node", meta_endpoint: "node/meta")
  @graph = graph
  @title = title
  @link = link
  @layout = layout
  @node_endpoint = node_endpoint
  @meta_endpoint = meta_endpoint
end

Instance Method Details

#renderObject



43
44
45
# File 'lib/okf/server/graph.rb', line 43

def render
  ERB.new(File.read(TEMPLATE, encoding: "UTF-8")).result(binding)
end