Skip to content

tdfs4ds.lineage.flow

tdfs4ds.lineage.flow

Zoomable left-to-right lineage view ("Flow") for the admin app (0.3.1.240).

The Sankey diagram does not scale: on a real workflow the links cross and the labels overlap, and it cannot be zoomed. This view keeps its reading order (sources on the left, datasets on the right) and adds interaction:

  • zoom and pan (wheel, drag, navigation buttons) and a Fit button;
  • a click on an object highlights its whole upstream and downstream path and dims the rest (click the background to clear), and posts the object's name to the page embedding it, so the admin app can show its documentation;
  • a search box zooms to matching objects;
  • filters: hide source tables, hide managers, or show processes and datasets only (intermediate views collapsed into the edges they connect).

:func:flow_model is pure (tested offline); :func:plot_lineage_flow returns one self-contained HTML page with vis-network inlined from the pyvis package, so it works offline and makes no external request.

KIND_STYLE module-attribute

KIND_STYLE = {'table': {'color': '#31a354', 'shape': 'box', 'label': 'source table'}, 'view': {'color': '#6baed6', 'shape': 'box', 'label': 'intermediate view'}, 'process': {'color': '#e6550d', 'shape': 'box', 'label': 'process view'}, 'dataset': {'color': '#756bb1', 'shape': 'box', 'label': 'dataset'}, 'time manager': {'color': '#f2b705', 'shape': 'diamond', 'label': 'TimeManager'}, 'filter manager': {'color': '#c9a227', 'shape': 'diamond', 'label': 'FilterManager'}, 'manager table': {'color': '#d9c27a', 'shape': 'box', 'label': 'manager table'}, 'unknown': {'color': '#bdbdbd', 'shape': 'box', 'label': 'other'}}

_KEEP_COMPACT module-attribute

_KEEP_COMPACT = {'process', 'dataset'}

MANAGER_KINDS module-attribute

MANAGER_KINDS = frozenset({'time manager', 'filter manager', 'manager table'})

_PLURAL module-attribute

_PLURAL = {'view': 'views', 'table': 'tables', 'process': 'process views', 'dataset': 'datasets', 'time manager': 'time managers', 'filter manager': 'filter managers', 'manager table': 'manager tables', 'unknown': 'objects'}

_CSS module-attribute

_CSS = '\nbody{margin:0;font-family:Inter,Arial,sans-serif;background:#fff;color:#14273A}\n#bar{display:flex;flex-wrap:wrap;gap:10px;align-items:center;padding:8px 10px;border-bottom:1px solid #E2E8F0;\n     background:#F7F8FA;font-size:13px}\n#bar input[type=search]{padding:4px 8px;border:1px solid #CBD5E1;border-radius:6px;min-width:200px}\n#bar button{padding:4px 10px;border:1px solid #00233C;background:#00233C;color:#fff;border-radius:6px;cursor:pointer}\n#bar label{display:flex;gap:4px;align-items:center;cursor:pointer}\n#wrap{position:absolute;top:44px;bottom:28px;left:0;right:0;display:flex}\n#side{width:260px;flex:none;display:flex;flex-direction:column;border-right:1px solid #E2E8F0;background:#F7F8FA;font-size:12px}\n#side.closed{display:none}\n#sum{padding:8px 10px;color:#14273A;border-bottom:1px solid #E2E8F0;line-height:1.35}\n#tabs{display:flex;border-bottom:1px solid #E2E8F0}\n#tabs button{flex:1;padding:6px;border:0;background:none;cursor:pointer;font-size:12px;color:#5A6B7B}\n#tabs button.on{color:#00233C;font-weight:700;border-bottom:2px solid #FF5F00}\n#sideq{margin:6px 8px;padding:4px 8px;border:1px solid #CBD5E1;border-radius:6px}\n#grp-l{margin:0 8px 6px;display:flex;gap:4px;align-items:center;cursor:pointer}\n#list{flex:1;overflow-y:auto;padding-bottom:8px}\n.row{padding:6px 10px;cursor:pointer;border-left:3px solid transparent;border-bottom:1px solid #EEF1F5}\n.row:hover{background:#EEF1F5}\n.row.sel{background:#FFE9DA;border-left-color:#FF5F00}\n.row b{display:block;font-weight:600;word-break:break-word}\n.row span{color:#5A6B7B}\n#net{flex:1;position:relative;min-width:0}\n#legend{position:absolute;bottom:0;left:0;right:0;height:28px;display:flex;gap:14px;align-items:center;\n        padding:0 10px;font-size:12px;border-top:1px solid #E2E8F0;background:#fff;overflow:hidden}\n.sw{display:inline-block;width:11px;height:11px;border-radius:2px;margin-right:4px;vertical-align:-1px}\n#info{margin-left:auto;color:#5A6B7B;white-space:nowrap}\n'

_JS module-attribute

_JS = '\n(function(){\nvar M = __MODEL__, STYLE = __STYLE__;\nvar LARGE = 120, MIN_COMPACT = 15, MIN_CLUSTER = 7;\nvar PLURAL = {\'view\':\'views\',\'table\':\'tables\',\'process\':\'process views\',\'dataset\':\'datasets\',\'time manager\':\'time managers\',\n              \'filter manager\':\'filter managers\',\'manager table\':\'manager tables\',\'unknown\':\'objects\'};\nvar nodes = new vis.DataSet(), edges = new vis.DataSet();\nvar byId = {}; M.nodes.forEach(function(n){ byId[n.id] = n; });\nvar CL = M.clusters || [], clusterOf = {}, clById = {};\nCL.forEach(function(c){ clById[c.id] = c; c.members.forEach(function(m){ clusterOf[m] = c; }); });\nvar up = {}, down = {};   // up[x] = sources x reads, down[x] = consumers of x\nM.edges.forEach(function(e){ (down[e.from] = down[e.from] || []).push(e.to); (up[e.to] = up[e.to] || []).push(e.from); });\nvar state = {hideTables:false, showTM:true, showFM:true, touched:false, compact:false, focus:null, sel:null, selId:\'all\',\n             group:false, tab:\'seg\', filter:\'\', autos:{managers:false, compact:false}, note:\'\', skipped:\'\',\n             expanded:{}, singlesOpen:false, tiled:false, selMgr:{}, drawnCount:0};\nfunction isMgr(n){ return n.kind === \'time manager\' || n.kind === \'filter manager\' || n.kind === \'manager table\'; }\nfunction ck(id){ return document.getElementById(id).checked; }\nfunction setCk(id, v){ document.getElementById(id).checked = v; }\n\nfunction visible(n){\n  if (state.sel && !state.sel[n.id] && !state.selMgr[n.id]) return false;\n  if (state.compact) return n.kind === \'process\' || n.kind === \'dataset\';\n  if (state.hideTables && n.kind === \'table\') return false;\n  if (!mgrShown(n)) return false;\n  return true;\n}\n// TimeManagers / FilterManagers are shown independently; a manager table follows the\n// manager that reads it (shown when either toggle is on if its owner is unknown)\nfunction mgrShown(n){\n  if (n.kind === \'time manager\') return state.showTM;\n  if (n.kind === \'filter manager\') return state.showFM;\n  if (n.kind === \'manager table\'){\n    var ow = (down[n.id] || []).map(function(i){ return byId[i]; })\n      .filter(function(m){ return m && (m.kind === \'time manager\' || m.kind === \'filter manager\'); });\n    if (ow.length) return ow.some(function(m){ return m.kind === \'time manager\' ? state.showTM : state.showFM; });\n    return state.showTM || state.showFM;\n  }\n  return true;\n}\n// managers a set of objects needs (same rule as flow.managers_of): every manager of a group\n// read by one of them, so the clock and its clones come together; the toggles then filter by kind\nvar groupsOfReader = {}, clockOf = {};\n(M.manager_groups || []).forEach(function(g){\n  g.readers.forEach(function(r){ (groupsOfReader[r] = groupsOfReader[r] || []).push(g); });\n  if (g.clock) clockOf[g.clock] = g;\n});\nfunction managersOf(ids){\n  var have = {}, seen = {}, out = [];\n  ids.forEach(function(i){ have[i] = 1; });\n  ids.forEach(function(i){\n    (groupsOfReader[i] || []).forEach(function(g){\n      if (seen[g.id]) return; seen[g.id] = 1;\n      g.nodes.forEach(function(n){ if (!have[n]) out.push(n); });\n    });\n  });\n  return out;\n}\nfunction clockReaders(n){\n  var g = clockOf[n.id]; if (!g) return [];\n  return g.readers.filter(function(r){ return !state.sel || state.sel[r]; });\n}\nfunction labelOf(n){\n  var r = clockReaders(n);\n  return r.length >= 2 ? n.label + \'\\n[domain clock, \' + r.length + \' readers]\' : n.label;\n}\nfunction titleOf(n, s){\n  var t = n.database + \'.\' + n.label + \'\\n\' + s.label, r = clockReaders(n);\n  if (r.length >= 2) t += \'\\nDomain clock, read by:\\n\' + r.slice(0, 30).map(function(i){ return byId[i] ? byId[i].label : i; }).join(\'\\n\') + (r.length > 30 ? \'\\n...\' : \'\');\n  return t;\n}\n// the objects that would be drawn: visible nodes, fan-out clusters collapsed into one node\nfunction plan(){\n  var vis = M.nodes.filter(visible), per = {};\n  vis.forEach(function(n){ var c = clusterOf[n.id]; if (c && !state.expanded[c.id]) (per[c.id] = per[c.id] || []).push(n.id); });\n  var coll = {};\n  Object.keys(per).forEach(function(k){ if (per[k].length >= MIN_CLUSTER) coll[k] = per[k]; });\n  return {vis: vis, coll: coll};\n}\nfunction countDrawn(){\n  var p = plan(), n = p.vis.length;\n  Object.keys(p.coll).forEach(function(k){ n -= p.coll[k].length - 1; });\n  return n;\n}\nfunction upstream(start){\n  var keep = {}; keep[start] = 1; var st = [start];\n  while (st.length){ var x = st.pop(); (up[x] || []).forEach(function(y){ if (!keep[y]){ keep[y] = 1; st.push(y); } }); }\n  return keep;\n}\nfunction closure(start){\n  var keep = {}; keep[start] = 1;\n  [up, down].forEach(function(adj){\n    var seen = {}, st = [start];\n    while (st.length){\n      var x = st.pop();\n      (adj[x] || []).forEach(function(y){ if (!seen[y]){ seen[y] = 1; keep[y] = 1; st.push(y); } });\n    }\n  });\n  return keep;\n}\nfunction clusterTitle(mem){\n  var k = byId[mem[0]].kind, names = mem.map(function(i){ return byId[i].label; }).sort();\n  return {label: mem.length + \' \' + (PLURAL[k] || \'objects\') + \'\\n(\' + names[0] + \' ... \' + names[names.length - 1] + \')\',\n          title: mem.length + \' \' + (PLURAL[k] || \'objects\') + \' (click to expand)\\n\' + names.slice(0, 30).join(\'\\n\') +\n                 (names.length > 30 ? \'\\n... and \' + (names.length - 30) + \' more\' : \'\')};\n}\nfunction draw(){\n  var keep = state.focus ? closure(state.focus) : null;\n  var p = plan(), ns = [], es = [], did = {};\n  p.vis.forEach(function(n){\n    var c = clusterOf[n.id];\n    if (c && p.coll[c.id]) return;\n    var s = STYLE[n.kind] || STYLE.unknown, dim = keep && !keep[n.id];\n    ns.push({id:n.id, label:labelOf(n), level:n.level, shape:s.shape,\n             title: titleOf(n, s),\n             color:{background: dim ? \'#EEF1F5\' : s.color, border: n.id === state.focus ? \'#00233C\' : (dim ? \'#E2E8F0\' : s.color)},\n             font:{color: dim ? \'#B8C2CC\' : (n.kind === \'dataset\' || n.kind === \'process\' ? \'#fff\' : \'#14273A\'), size:13},\n             borderWidth: n.id === state.focus ? 3 : 1});\n  });\n  Object.keys(p.coll).forEach(function(k){\n    var mem = p.coll[k], n0 = byId[mem[0]], s = STYLE[n0.kind] || STYLE.unknown, t = clusterTitle(mem);\n    var dim = keep && !mem.some(function(m){ return keep[m]; });\n    ns.push({id:k, label:t.label, title:t.title, level:n0.level, shape:s.shape, borderWidth:2,\n             shapeProperties:{borderDashes:[6,4]},\n             color:{background: dim ? \'#EEF1F5\' : s.color, border: dim ? \'#E2E8F0\' : \'#00233C\'},\n             font:{color: dim ? \'#B8C2CC\' : (n0.kind === \'dataset\' || n0.kind === \'process\' ? \'#fff\' : \'#14273A\'), size:13, multi:false}});\n  });\n  function dn(id){ var c = clusterOf[id]; return (c && p.coll[c.id]) ? c.id : id; }\n  var list = state.compact ? M.compact_edges : M.edges, k = 0;\n  list.forEach(function(e){\n    if (!byId[e.from] || !byId[e.to] || !visible(byId[e.from]) || !visible(byId[e.to])) return;\n    var f = dn(e.from), t = dn(e.to), key = f + \'|\' + t + \'|\' + (e.driver ? 1 : 0);\n    if (did[key]) return; did[key] = 1;\n    var dim = keep && !(keep[e.from] && keep[e.to]);\n    es.push({id:\'e\'+(k++), from:f, to:t, arrows:\'to\', dashes: !!e.driver,\n             title: e.via ? (\'through \' + e.via + \' intermediate object(s)\') : (e.driver ? \'driver\' : \'\'),\n             color:{color: dim ? \'#EEF1F5\' : (e.driver ? (STYLE[byId[e.from].kind] || STYLE.unknown).color : \'#94A3B8\')}, width: dim ? 1 : 1.5});\n  });\n  var tiled = !state.sel;\n  if (tiled !== state.tiled){ nodes.clear(); edges.clear(); net.setOptions({layout:{hierarchical: tiled ? false : HIER, improvedLayout:false}}); state.tiled = tiled; }\n  if (tiled) packAll(ns, p);\n  nodes.clear(); edges.clear(); nodes.add(ns); edges.add(es);\n  state.placed = tiled ? ns : null;\n  state.drawnCount = ns.length;\n  var nc = Object.keys(p.coll).length, folded = 0;\n  Object.keys(p.coll).forEach(function(k){ folded += p.coll[k].length; });\n  document.getElementById(\'info\').textContent = ns.length + \' objects\' +\n    (nc ? \' (\' + nc + \' cluster\' + (nc > 1 ? \'s\' : \'\') + \' standing for \' + folded + \' objects)\' : \'\') +\n    (ns.length === 0 ? \' - nothing to draw\' + (state.compact ? \': compact keeps only processes and datasets, this selection has none\' : \'\') : \'\') +\n    \', \' + es.length + \' links\' + (M.cycles.length ? \' - \' + M.cycles.length + \' cycle(s)\' : \'\') +\n    (state.note ? \' - \' + state.note : \'\') + (state.skipped ? \' - \' + state.skipped : \'\') +\n    (state.compact && (state.showTM || state.showFM) ? \' - compact view hides managers and tables\' : \'\');\n}\nvar HIER = {enabled:true, direction:\'LR\', sortMethod:\'directed\', levelSeparation:230, nodeSpacing:60,\n            treeSpacing:80, blockShifting:true, edgeMinimization:true, parentCentralization:true};\n// All view: the segments are tiled as blocks (each keeps its columns) instead of one tall stack\nfunction packAll(ns, p){\n  var segOf = {}; M.segments.forEach(function(s){ s.nodes.forEach(function(i){ segOf[i] = s.id; }); });\n  var groups = {};\n  ns.forEach(function(n){ var m = p.coll[n.id] ? p.coll[n.id][0] : n.id; var k = segOf[m] || \'x\'; (groups[k] = groups[k] || []).push(n); });\n  var blocks = Object.keys(groups).map(function(k){\n    var g = groups[k], lv = {}, maxL = 0, rows = 0;\n    g.forEach(function(n){ var l = n.level || 0; (lv[l] = lv[l] || []).push(n); if (l > maxL) maxL = l; });\n    Object.keys(lv).forEach(function(l){ lv[l].sort(function(a, b){ return a.label < b.label ? -1 : 1; }); rows = Math.max(rows, lv[l].length); });\n    return {lv:lv, w:(maxL + 1) * 270 + 60, h:rows * 54 + 60};\n  });\n  blocks.sort(function(a, b){ return b.h - a.h; });\n  var area = 0; blocks.forEach(function(b){ area += b.w * b.h; });\n  var W = Math.max(2600, Math.sqrt(area) * 1.5), x = 0, y = 0, rowH = 0;\n  blocks.forEach(function(b){\n    if (x > 0 && x + b.w > W){ x = 0; y += rowH; rowH = 0; }\n    Object.keys(b.lv).forEach(function(l){ b.lv[l].forEach(function(n, i){ n.x = x + l * 270; n.y = y + i * 54; n.fixed = true; }); });\n    x += b.w; rowH = Math.max(rowH, b.h);\n  });\n}\nvar net = new vis.Network(document.getElementById(\'net\'), {nodes:nodes, edges:edges}, {\n  layout:{hierarchical:HIER, improvedLayout:false},\n  physics:false, interaction:{navigationButtons:true, keyboard:true, hover:true, zoomView:true, dragView:true, tooltipDelay:120},\n  edges:{smooth:{type:\'cubicBezier\', forceDirection:\'horizontal\', roundness:0.4}},\n  nodes:{margin:8, widthConstraint:{maximum:220}}\n});\nfunction place(){ if (state.placed) state.placed.forEach(function(n){ net.moveNode(n.id, n.x, n.y); }); }\nfunction fitNow(){ net.fit(); if (state.drawnCount < 40 && net.getScale() < 0.65) net.moveTo({scale: 0.65}); }\nfunction refit(){ place(); fitNow(); setTimeout(function(){ place(); fitNow(); }, 120); }\nfunction setCluster(id, open){\n  if (open) state.expanded[id] = 1; else delete state.expanded[id];\n  state.focus = null; renderList(); draw(); refit();\n}\nnet.on(\'click\', function(p){\n  if (p.nodes.length){\n    var id = p.nodes[0];\n    if (clById[id]){ setCluster(id, true); return; }\n    state.focus = id;\n    try { window.parent.postMessage({type:\'tdfs4ds-lineage-node\', node: state.focus}, \'*\'); } catch(e) {}\n  } else { state.focus = null; }\n  draw();\n});\nnet.on(\'doubleClick\', function(p){\n  if (!p.nodes.length) return;\n  var c = clusterOf[p.nodes[0]];\n  if (c && state.expanded[c.id]) setCluster(c.id, false);\n});\n\n// ---- large-graph defaults -------------------------------------------------\nfunction syncGroup(){\n  var g = document.getElementById(\'grp\'), on = state.showTM || state.showFM;\n  g.disabled = !on;\n  document.getElementById(\'grp-l\').title = on ? \'\' : \'Turn on TimeManagers or FilterManagers to group the segments by driver\';\n  if (!on && state.group){ state.group = false; g.checked = false; }\n}\nfunction applyLarge(){\n  state.autos = {managers:false, compact:false}; state.note = \'\'; state.skipped = \'\';\n  state.showTM = ck(\'t-tm\'); state.showFM = ck(\'t-fm\'); state.compact = ck(\'t-compact\');\n  if (state.sel) { syncGroup(); return; }\n  var total = M.nodes.length;\n  if (total > LARGE && !state.touched && (state.showTM || state.showFM)){\n    state.showTM = false; state.showFM = false; setCk(\'t-tm\', false); setCk(\'t-fm\', false); state.autos.managers = true;\n  }\n  syncGroup();\n  if (countDrawn() > LARGE && !state.compact){\n    state.compact = true;\n    var left = countDrawn();\n    if (left >= MIN_COMPACT){ state.autos.compact = true; setCk(\'t-compact\', true); }\n    else { state.compact = false; state.skipped = "\'processes and datasets only\' not applied: it would leave only " + left + \' objects\'; }\n  }\n  if (state.autos.managers || state.autos.compact)\n    state.note = \'Large graph: showing \' + countDrawn() + \' of \' + total + \' objects (managers hidden\' +\n      (state.autos.compact ? \', processes and datasets only\' : \'\') + \'), pick a segment to read one pipeline\';\n}\nfunction undoAutos(){\n  if (state.autos.managers){ state.showTM = true; state.showFM = true; setCk(\'t-tm\', true); setCk(\'t-fm\', true); }\n  if (state.autos.compact){ state.compact = false; setCk(\'t-compact\', false); }\n  state.autos = {managers:false, compact:false}; state.note = \'\'; state.skipped = \'\';\n  syncGroup();\n}\n\n// ---- side panel -----------------------------------------------------------\n// segments as shown: members and counts follow the manager toggles; a segment with nothing left disappears\nfunction segs(){\n  var src = state.group ? M.segments_with_drivers : M.segments, out = [];\n  src.forEach(function(s){\n    var ns = s.nodes.filter(function(i){ return mgrShown(byId[i]); });\n    if (!ns.length) return;\n    var c = {process:0, dataset:0, view:0, table:0, manager:0};\n    ns.forEach(function(i){ var k = byId[i].kind; c[isMgr(byId[i]) ? \'manager\' : (k in c ? k : \'view\')]++; });\n    out.push({id:s.id, label:s.label, size:ns.length, counts:c, nodes:ns,\n              linked_by:(s.linked_by || []).filter(function(i){ return byId[i] && mgrShown(byId[i]); })});\n  });\n  return out;\n}\nfunction singles(){ return segs().filter(function(s){ return s.size < 2; }); }\nfunction setOf(ids){ var o = {}; ids.forEach(function(i){ o[i] = 1; }); return o; }\nfunction select(id){\n  var set = null;\n  if (id === \'all\'){ set = null; }\n  else if (id === \'single\'){ var ids = []; singles().forEach(function(s){ ids = ids.concat(s.nodes); }); set = setOf(ids); }\n  else if (id.indexOf(\'b:\') === 0){ set = upstream(id.slice(2)); }\n  else {\n    if (id.charAt(0) === \'g\' && !state.group){ state.group = true; setCk(\'grp\', true); }\n    if (id.charAt(0) === \'s\' && state.group){ state.group = false; setCk(\'grp\', false); }\n    var f = segs().filter(function(s){ return s.id === id; })[0];\n    if (!f){ id = \'all\'; } else { set = setOf(f.nodes); }\n  }\n  state.selId = id; state.sel = set; state.focus = null;\n  state.selMgr = {}; if (set) managersOf(Object.keys(set)).forEach(function(m){ state.selMgr[m] = 1; });\n  if (set) undoAutos(); else applyLarge();\n  renderList(); draw(); refit();\n  if (id.indexOf(\'b:\') !== 0){\n    try { window.parent.postMessage({type:\'tdfs4ds-lineage-segment\', id: id}, \'*\'); } catch(e) {}\n  }\n}\nfunction mkRow(id, title, sub, onclick){\n  var r = document.createElement(\'div\'); r.className = \'row\' + (state.selId === id ? \' sel\' : \'\');\n  var b = document.createElement(\'b\'); b.textContent = title; var s = document.createElement(\'span\'); s.textContent = sub;\n  r.appendChild(b); r.appendChild(s); r.onclick = onclick || function(){ select(id); };\n  return r;\n}\nfunction extraManagers(s){\n  if (!state.showTM && !state.showFM) return \'\';\n  var n = managersOf(s.nodes).filter(function(i){ return !isMgr(byId[i]) ? false : byId[i].kind !== \'manager table\' && mgrShown(byId[i]); }).length;\n  return n ? \' · +\' + n + \' managers\' : \'\';\n}\nfunction renderList(){\n  var box = document.getElementById(\'list\'); box.innerHTML = \'\';\n  var q = state.filter.toUpperCase();\n  function match(txt){ return !q || txt.toUpperCase().indexOf(q) >= 0; }\n  if (state.tab === \'seg\'){\n    box.appendChild(mkRow(\'all\', \'All\', M.nodes.length + \' objects\'));\n    segs().filter(function(s){ return s.size >= 2; }).forEach(function(s){\n      if (!match(s.label + \' \' + s.nodes.join(\' \'))) return;\n      var c = s.counts;\n      box.appendChild(mkRow(s.id, s.label, s.size + \' objects · \' + c.process + \' processes · \' + c.dataset + \' datasets\' +\n        (!state.group && s.linked_by && s.linked_by.length ? \' · linked by \' + s.linked_by.length + \' driver(s)\' : \'\') +\n        extraManagers(s)));\n    });\n    var sg = singles(), names = [];\n    sg.forEach(function(s){ names = names.concat(s.nodes); });\n    names = names.sort();\n    var shown = names.filter(function(i){ return match(byId[i].database + \'.\' + byId[i].label); });\n    if (sg.length && (!q || shown.length || match(\'single objects\'))){\n      var row = mkRow(\'single\', \'Single objects (\' + sg.length + \')\',\n                      (state.singlesOpen ? \'click to draw them all\' : \'no link once drivers are ignored\'));\n      var tg = document.createElement(\'a\'); tg.textContent = state.singlesOpen ? \' [hide names]\' : \' [show names]\';\n      tg.style.cssText = \'color:#FF5F00;margin-left:6px;cursor:pointer\';\n      tg.onclick = function(ev){ ev.stopPropagation(); state.singlesOpen = !state.singlesOpen; renderList(); };\n      row.lastChild.appendChild(tg); box.appendChild(row);\n      if (state.singlesOpen || q) shown.forEach(function(i){\n        var r = mkRow(\'b:\' + i, byId[i].label, (STYLE[byId[i].kind] || STYLE.unknown).label);\n        r.style.paddingLeft = \'22px\'; box.appendChild(r);\n      });\n    }\n  } else if (state.tab === \'cl\'){\n    if (!CL.length) box.textContent = \'No fan-out cluster (needs \' + MIN_CLUSTER + \' or more objects of one kind with the same sources and consumers).\';\n    CL.forEach(function(c){\n      if (!match(c.label + \' \' + c.members.join(\' \'))) return;\n      var open = !!state.expanded[c.id];\n      var t = clusterTitle(c.members);\n      box.appendChild(mkRow(\'cl:\' + c.id, t.label.replace(\'\\n\', \' \'), (open ? \'expanded - click to collapse\' : \'collapsed - click to expand\'),\n                            function(){ setCluster(c.id, !open); }));\n      if (open) c.members.forEach(function(m){\n        if (!match(byId[m].label)) return;\n        var r = mkRow(\'b:\' + m, byId[m].label, \'\'); r.style.paddingLeft = \'22px\'; box.appendChild(r);\n      });\n    });\n  } else {\n    [[\'dataset\', \'dataset\'], [\'process\', \'process view\']].forEach(function(kk){\n      M.nodes.filter(function(n){ return n.kind === kk[0]; })\n        .sort(function(a, b){ return a.label < b.label ? -1 : (a.label > b.label ? 1 : 0); })\n        .forEach(function(n){\n          if (!match(n.label + \' \' + n.database)) return;\n          box.appendChild(mkRow(\'b:\' + n.id, n.label, kk[1] + \' · \' + Object.keys(upstream(n.id)).length + \' objects upstream\'));\n        });\n    });\n  }\n  if (!box.children.length) box.textContent = \'Nothing matches.\';\n}\n(function(){\n  var S = M.summary || {};\n  var t = (S.n_objects || 0) + \' objects: \' + (S.n_segments_with_drivers || 0) +\n    \' segments (\' + (S.n_segments || 0) + \' when drivers are ignored, \' + (S.n_segments_with_processes || 0) +\n    \' with processes), \' + (S.n_shared_drivers || 0) + \' shared drivers, \' + (S.n_single || 0) + \' single objects\';\n  if ((S.n_process_views || 0) < 5) t += \'. Only \' + (S.n_process_views || 0) + \' process view(s) registered\';\n  document.getElementById(\'sum\').textContent = t;\n})();\n[\'seg\', \'br\', \'cl\'].forEach(function(k){\n  document.getElementById(\'tab-\' + k).onclick = function(){\n    state.tab = k;\n    [\'seg\', \'br\', \'cl\'].forEach(function(j){ document.getElementById(\'tab-\' + j).className = (j === k ? \'on\' : \'\'); });\n    renderList();\n  };\n});\ndocument.getElementById(\'sideq\').addEventListener(\'input\', function(){ state.filter = this.value.trim(); renderList(); });\ndocument.getElementById(\'grp\').addEventListener(\'change\', function(){\n  var prev = state.selId, key = null;\n  if (prev !== \'all\' && prev !== \'single\' && prev.indexOf(\'b:\') !== 0){\n    var cur = segs().filter(function(x){ return x.id === prev; })[0];\n    if (cur){\n      var pd = cur.nodes.filter(function(i){ return byId[i].kind === \'process\' || byId[i].kind === \'dataset\'; });\n      key = pd[0] || cur.nodes.filter(function(i){ return !isMgr(byId[i]); })[0] || cur.nodes[0];\n    }\n  }\n  state.group = this.checked;\n  if (prev === \'all\' || prev.indexOf(\'b:\') === 0 || prev === \'single\'){ renderList(); return; }\n  var ns = segs().filter(function(x){ return key && x.nodes.indexOf(key) >= 0; })[0];\n  if (ns) select(ns.id);\n  else { select(\'all\'); state.note = \'the selected segment does not exist with this grouping\'; draw(); }\n});\ndocument.getElementById(\'side-toggle\').onclick = function(){\n  var sd = document.getElementById(\'side\'); sd.className = sd.className === \'closed\' ? \'\' : \'closed\';\n  setTimeout(function(){ net.redraw(); refit(); }, 50);\n};\nwindow.addEventListener(\'message\', function(e){\n  if (e.source !== window.parent) return;\n  var d = e.data || {};\n  if (d.type === \'tdfs4ds-lineage-select-segment\' && typeof d.id === \'string\') select(d.id);\n});\n\ndocument.getElementById(\'fit\').onclick = function(){ net.fit({animation:true}); };\n// Reset = the defaults of the large-graph rule: nothing filtered, nothing expanded, no user choice remembered\ndocument.getElementById(\'reset\').onclick = function(){\n  state.expanded = {}; state.touched = false; state.hideTables = false; state.group = false;\n  setCk(\'t-tables\', false); setCk(\'t-compact\', false); setCk(\'t-tm\', true); setCk(\'t-fm\', true); setCk(\'grp\', false);\n  state.showTM = true; state.showFM = true; state.compact = false; state.filter = \'\';\n  document.getElementById(\'sideq\').value = \'\'; document.getElementById(\'q\').value = \'\'; state.singlesOpen = false;\n  select(\'all\');\n};\ndocument.getElementById(\'q\').addEventListener(\'input\', function(){\n  var q = this.value.trim().toUpperCase(); if (!q) { net.unselectAll(); return; }\n  var hits = M.nodes.filter(function(n){ return visible(n) && (n.database + \'.\' + n.label).toUpperCase().indexOf(q) >= 0; })\n                    .map(function(n){ return n.id; });\n  var open = false;\n  hits.forEach(function(h){ var c = clusterOf[h]; if (c && !state.expanded[c.id]){ state.expanded[c.id] = 1; open = true; } });\n  if (open){ renderList(); draw(); }\n  net.selectNodes(hits); if (hits.length) net.fit({nodes:hits, animation:true});\n});\n[[\'t-tables\',\'hideTables\'],[\'t-tm\',\'showTM\'],[\'t-fm\',\'showFM\'],[\'t-compact\',\'compact\']].forEach(function(p){\n  document.getElementById(p[0]).addEventListener(\'change\', function(){\n    state[p[1]] = this.checked;\n    if (p[1] === \'showTM\' || p[1] === \'showFM\'){ state.touched = true; state.autos.managers = false; syncGroup(); }\n    if (p[1] === \'compact\') state.autos.compact = false;\n    state.note = \'\'; state.skipped = \'\';   // a note about the automatic defaults no longer describes what is drawn\n    if (p[1] !== \'hideTables\' && p[1] !== \'compact\' && state.selId.charAt(0) === \'g\' && !state.group){ select(\'all\'); return; }\n    renderList(); draw(); refit();\n  });\n});\napplyLarge(); renderList(); draw(); refit();\n})();\n'

_kind

_kind(meta: dict, node_id: str, process_views) -> str

flow_model

flow_model(graph: Dict[str, Any], process_views: Optional[Iterable[str]] = None) -> Dict[str, Any]

Nodes with a column (depth) and a kind, data-flow edges, compact edges.

graph: {'nodes', 'edges'} as :func:lineage_store.get_persisted_graph returns it (edge = parent -> child = consumer -> source). process_views: node ids ('DB.OBJECT') of registered process views.

Columns: a source (reads nothing) is in column 0, every other object one column right of its deepest source, so data flows left to right as in the Sankey. A cycle (reported in cycles) is placed as one block.

_common_prefix

_common_prefix(names) -> str

Longest common prefix of names; '' when it is shorter than 3 characters.

segment_label

segment_label(members: Iterable[str], by_id: Dict[str, dict], max_names: int = 2, degree: Optional[Dict[str, int]] = None) -> str

Readable name of a segment.

With datasets (else processes): their names, +n more. Without either: its hub (the object with most links, degree) and the common name prefix of the other members, e.g. TMP_X_* (44 views from TMP_X_SRC); with no common prefix, <hub> +n more.

find_clusters

find_clusters(flow_edges, by_id, min_size: int = 7) -> list

Fan-out clusters: more than min_size - 1 objects of one kind with exactly the same parents (sources) and the same children (consumers).

{id, kind, label, members, parents, children}; manager (driver) links are ignored, and objects with no data-flow link are never grouped. Ordered by size (descending), kind, first member.

build_segments

build_segments(node_ids, flow_edges, by_id, *, include_drivers: bool, prefix: str) -> list

Weakly connected components of the data-flow graph as segments.

With include_drivers=False the manager edges (driver) are ignored, so two pipelines tied only by a shared clock are two segments. Each segment is {id, size, counts{process,dataset,view,table,manager}, label, nodes, linked_by} (linked_by is filled by the caller). Ordering is deterministic: size descending, then label, then first node id; ids are <prefix>1, <prefix>2...

shared_drivers

shared_drivers(G, segments: list, by_id: Dict[str, dict]) -> list

Manager groups that join two or more segments (computed without manager edges).

Managers that touch each other (a clock, its clones and their hidden table) form one group; the group counts a segment only when that segment holds a non-manager object, so a hidden table never inflates the figure. The group is named by its best connected member (members lists them all). Sorted by number of segments joined (descending), then label.

manager_groups

manager_groups(flow_edges, by_id) -> list

Groups of managers that touch each other (a clock, its clones and their hidden table), with the non-manager objects that read them.

{id, nodes, readers, clock}: clock is the TimeManager view that owns the group's hidden table (same name without _HIDDEN) when the group has two or more readers; a TimeManager read directly by two or more objects is also a clock. None otherwise. Ordered by size (descending), then id.

managers_of

managers_of(nodes, groups, by_id, kinds=('time manager', 'filter manager')) -> list

Managers a set of objects needs: every manager of the given kinds in a group read by at least one of nodes (so the clock and its clones come together), plus the hidden tables of the groups touched. Nodes already in nodes are not repeated. The page applies the same rule in JavaScript.

_compact_edges

_compact_edges(G, kinds) -> list

Edges between processes and datasets only: an intermediate object between them is folded into the edge (via = how many objects were folded).

_vis_js

_vis_js() -> str

vis-network, inlined from the pyvis package (newest bundled version).

plot_lineage_flow

plot_lineage_flow(graph: Dict[str, Any], *, process_views=None, output_path: Optional[str] = None, title: str = 'Lineage') -> str

The Flow view as one self-contained HTML page (returned, and written to output_path when given).