OSINT

Teaching a network chart to arrange itself the way an investigator would

Discover how Public Insights' network canvas uses innovative layout engines to create intuitive network charts, making complex data easily understandable for investigators.


There are no hard and fast rules about where things go on a network chart. Ask ten investigators to draw the same ownership structure and you will get ten charts. But look at them side by side and the same habits show up. Owners tend to sit above what they own. Directors sit above their companies. Addresses drift to the bottom where they stay out of the way. Lines go round boxes, not through them. A group of companies under one parent gets a box drawn round it. Nobody was taught these as rules. They are what people arrive at when they want a chart someone else can read.

Most link-analysis tools come with a handful of prebuilt network algorithms, and they are never quite right. They were designed to show the shape of a graph: clusters, hubs, bridges. They do that well. What they cannot do is show who controls what, because they have no idea that an ownership link and a shared postcode are different kinds of thing. Everything is a dot on a spring.

At Public Insights, our network canvas is built on Cytoscape.js, and until now it used one of those prebuilt algorithms. We built a layout engine that arranges a chart the way an investigator would draw it. Then we fitted it into the canvas, where it has to work even while our AI assistant is adding to the chart. We call it the hierarchy view.

Every chart, name and label shown here is invented. The accuracy figures come from generated test networks, where the right answer is known because we built it.

01-force-vs-hierarchy

The same invented chart twice: as dots and straight lines, then arranged in rows with routed lines.

The idea: code does the geometry, a decider makes the calls

A layout like this has two kinds of work in it, and they are very different.

The first kind is geometry. Put these forty boxes in rows. Route a line from here to there without crossing a box. Find a clear stretch of line to hang a label on. That is arithmetic, and code should do all of it, quickly and the same way every time.

The second kind is judgement. Are these five companies really a group, or do they just share a formation agent? This person is in two groups: which box do they belong in? This link is awkward whichever way it is routed: is it important enough to keep prominent? An investigator makes those calls without noticing. Code cannot make them by arithmetic.

So the engine is built in two halves. The code proposes options and does the drawing. A “decider” answers the judgement questions. Each decision records the question, the answer, a confidence score and a reason.

ok, conf, why = decider.overlap(box_a, box_b, shared_members, structure)
decisions.append(Decision(f"overlap:{a}:{b}", "box_overlap", a,
                          "yes" if ok else "no", conf, why, source))

The first decider is a set of plain rules. That matters more than it sounds. With rules in the decider’s seat, the whole engine can be built, tested and measured before any model exists, and every model that comes later has a baseline to beat.

There are also hard rules that no decider can override. Every entity must stay inside its box. A line can only pass through an entity it belongs to. Two boxes can overlap only if both declare it. Every layout is checked against these rules. Our property tests throw random networks at the engine and fail if any hard rule breaks.

The models

Rules first, then a model for one question

The first question we handed to a model was box acceptance: given a candidate group, should it get a box?

The training data came from the generator that makes our test networks. It builds families of companies, trusts and people from templates, then makes them messy: decoy groups that look like families, formation-agent addresses shared by strangers, personal ties cutting across corporate ones. Because it built the network, it knows which groups are real.

On candidates it had never seen, the trained model was right 93% of the time. The plain rule managed 55%. The model now sits alongside the rules as a decider for that one question.

We also check ideas the old-fashioned way. Pairs of charts of the same network, laid out two ways, shown blind, and someone picks the better one. An idea that scores well on paper and makes no visible difference to the chart does not go in. A layout is for people to read, so people get the casting vote.

Reading link labels

This is the part that matters most for real data.

The engine needs to know three things about a link: what kind it is (control, a role, family, money, a location), who sits above whom, and whether it is out of date. On a tidy dataset you would have a type field. In the wild you have a label somebody typed. “dir.”, “ex dir”, “shareholder (25%)”, “banks via”, “gérant”, “sister of”, “see file”.

The first line of defence is a dictionary of several thousand phrases in English and eight other languages, each mapped to a kind and a direction. It is unglamorous and it works. To keep ourselves honest, we held back a set of label wordings from the dictionary’s authors and scored those separately.

Where the dictionary does not know the wording, something has to read it. We built two readers.

The first is a small multilingual text model with trained heads on top. Shrunk down, it is 118 MB.

The second came from asking whether the job really needed a language model at all. It is a reader built for this one task and nothing else. It is 0.22 MB and has no dependencies beyond NumPy. It runs locally, so no label has to leave the machine.

Here is how they compare inside the engine, counting a link as right only if all three parts are right.

Wording Dictionary alone With the tiny reader With the text model
Known wording (8,315 links) 98.0% 98.6% 98.7%
Other languages (3,220 links) 98.7% 99.8% 99.7%
Wording held back from the dictionary’s authors (5,065 links) 90.9% 92.2% 90.2%
Hand-picked awkward labels 84% 85% 86%

At about one five-hundredth the size, the tiny reader keeps pace with the text model and beats it on the wording we held back. So the tiny reader is the default everywhere.

Two rules sit around whichever reader is used. First, it only gets a say where the dictionary did not recognise the wording. Second, it must always decide. If it is unsure, it still gives its best answer. The link is flagged, and the engine falls back on what the entity types and the structure imply. An account is never drawn above a person, whatever any reader thinks.

A note on asking a model questions

For the awkward labels we also trialled a commercial decision model as a teacher: put the hard cases to it, and train the local reader on its answers. The trial used only invented data. The model stayed out of live operation.

The lesson from that trial had little to do with which model we asked. Our first attempt asked a broad question. The second asked a narrow one, put the evidence first, and spelled out exactly what counts as yes and what counts as no. The answers improved sharply. Same model, same data. They improved again once we wrote down the chart conventions we had been assuming everyone knew.

If you are putting judgement questions to a model, most of the quality is in the question.

What the layout has to do on screen

Boxes that overlap, and boxes that bend

Real groups overlap. A company can sit in an ownership group and in a shared-director network at once. Force every entity into exactly one box and one of the two groups loses a member, which means the chart tells a small lie.

So boxes can overlap, Venn style, with the shared entities in the overlap. To keep it readable, a box overlaps at most one other box, and only where both boxes claim the same member.

A group whose rows hold different numbers of members is drawn as a stepped outline that hugs them. That leaves the spare corner free for other entities and lines, making the chart more compact. Too many corners and a box stops reading as a box, so the outline is capped at eight.

 

03-boxes

One region of an invented chart three ways: one box per entity, overlapping boxes, and a stepped outline.

Split arrows

When one company owns six others, six separate lines leaving it is clutter. Drawing it by hand, you would take one line down and split it. The engine finds where routed lines share a stretch, draws it once, marks the split with a dot, and labels the shared stretch with what the links have in common.

It sounds cosmetic. It shaped the label placement more than anything else, because each link’s own label must sit on a stretch of line that belongs to that link alone. A label on the shared stem says something about all six.

Data that arrives in pieces

Charts do not arrive whole. You expand one node, then another. An assistant feeds you a batch every few seconds. And a late link can overturn an earlier placement. Halfway through, a new ownership link shows that the company you put in family A actually belongs under family B.

If the engine lays the chart out afresh each time, everything jumps and the user loses their place. If it refuses to move anything, the chart drifts away from the facts. So the engine tries both ways. If the two layouts score about the same, it keeps the one that moves less.

held = layout(graph, prior=prior, tweaks={"hold_columns": True, "force_box": was})
new = layout(graph, prior=prior)
c = compare(evaluate(graph, held, prev=prev), evaluate(graph, new, prev=prev))
# Within tolerance, the one that disturbs less wins.
choose_held = c == 1 or (c == 0 and moved(held) < moved(new))

To test it, we fed the same networks in as shuffled lists of links, in several random orders and batch sizes, so that late links really were late.

02-piece-by-piece

An invented network arriving five links at a time. Most steps hold what is already placed.

Measuring movement properly

The obvious way to measure disruption is to count the entities that changed position. It is nearly useless. If one row gets taller, everything below it slides down by the same amount. Seventy entities “moved” and the user’s picture of the chart is intact.

What matters is whether things kept their order. Is this company still left of that one? Is it still below its owner? So we measure the share of pairs of entities whose relative order is unchanged. We tested six networks in nine orders each, with holding enabled.

Links per step Order kept
3 95.9%
10 84.7%
30 62.8%

That drop-off led us to cap updates at five links per step. Bigger batches are split. The chart is never asked to swallow thirty links at once.

05-late-link
Before and after a late batch of links. The new entities find places, and the rest keep their order.

Looking back at close decisions

Every decision carries a confidence score, which invites an obvious refinement: go back to the closest calls, try them the other way, and keep the result if the chart is better.

When we ran that check after each change, it altered the chart in about 3% of steps. In those steps it moved around 60% of what was on screen. It rarely does anything, and when it does, it does a lot.

That is a fine property for a tidy-up the user asks for and a poor one for something that fires while they are reading. So the engine handles each update with the hold-or-rearrange decision alone and keeps the look-back separate. As a side effect, that cut the response time on our largest test chart by about three quarters.

Dragging

Users expect to drag things. But a routed line is a fixed shape. Drag an entity in a chart like this and its lines and its group box stay behind.

Our answer is to treat a drag as a request. Who owns or directs whom sets the entity’s row. The user can change its place among the entities in that row. While it is being dragged, its lines are drawn straight so they follow the mouse. On release, the engine puts it in the nearest allowed place and reroutes its lines.

In scripted tests, 82% of drags landed exactly where they were aimed. The rest stayed in the same row, and none broke a hard rule.

04-drag

A drag along a row. Lines go straight while the entity is held, then the engine reroutes them.

Making Cytoscape.js draw it

We expected to have to build our own charting component. We did not. Cytoscape.js 3.19, with no extensions, can draw all of the above. But almost none of it works the way you would first reach for.

Positions and routes

The Cytoscape layout is preset, and every position comes from the engine.

Routes were the part we were least sure of. Each link needed to stay one Cytoscape edge so it would still be one thing to click and select. Cytoscape’s segments curve style takes corner points. Each point is given as a weight along the straight line between the two nodes, plus a distance off that line. So every route has to be converted.

def segment_points(points, source_centre, target_centre):
    (sx, sy), (tx, ty) = source_centre, target_centre
    out = {"source_endpoint": [points[0][0] - sx, points[0][1] - sy],
           "target_endpoint": [points[-1][0] - tx, points[-1][1] - ty]}
    vx, vy = tx - sx, ty - sy
    length = math.hypot(vx, vy)
    ux, uy = vx / length, vy / length
    weights, distances = [], []
    for px, py in points[1:-1]:
        dx, dy = px - sx, py - sy
        weights.append((dx * ux + dy * uy) / length)  # how far along
        distances.append(-dx * uy + dy * ux)  # how far off, on Cytoscape's normal
    return dict(out, segment_weights=weights, segment_distances=distances)

Set edge-distances: node-position so Cytoscape measures from the centre of the node. Set the endpoints explicitly as offsets from each node, or Cytoscape picks its own.

A test converts every route to this form and back. Routes reproduce to within 0.002 units.

Drawing the group boxes

Cytoscape has groups, called compound nodes, and they look like the obvious way to draw a box. A compound node is always a rectangle. Two cannot overlap. A node has exactly one parent. That rules out stepped boxes, overlapping boxes and an entity in two groups.

So a box is an ordinary node drawn behind everything else. For a stepped box, we set shape: polygon and supply the corners of the outline. The box carries its membership as data and ignores the mouse, so clicks pass through to the entities.

Labels are nodes too

Cytoscape puts an edge’s label at the middle of the edge. On a routed line with a shared stem, the middle is often on the stem, which is exactly where a link’s own label must not go. So each label is a small text node, with its position and angle set by the engine. The junction dots are nodes as well.

A 100-entity chart becomes roughly 400 to 500 Cytoscape elements.

Colours and fonts as a theme

Every colour and font the export uses sits in one flat dictionary, so a host application can match its own look by passing overrides. If you use a web font, wait for it before you create the chart. Cytoscape draws text on a canvas and does not redraw when a font arrives late.

Animating from one layout to the next

When the chart changes, it should move, not blink. Entities and plain boxes can slide. Routed lines cannot: there is no sensible way to bend one cornered route into another with a different number of corners. So an update has three beats. Elements that are leaving or need to be redrawn fade out. Entities slide. New and redrawn parts fade in.

out.animate({ style: { opacity: 0 } }, { duration: fade });  // 1: fade
after(fade, function () {
  out.remove();
  slide.forEach(function (e) { e.animate({ position: next[e.id()].position },
                                         { duration: ms }); });  // 2: slide
  after(ms, function () {
    landed.forEach(function (it) { it[0].stop(); it[0].position(it[1].position); });
    var added = cy.add(fresh);  // 3: fade in
    added.animate({ style: { opacity: 1 } }, { duration: fade });
    after(fade + 20, function () { added.stop(); added.removeStyle('opacity'); done(); });
  });
});

Look at the stop() calls and the timers. Cytoscape animations run on animation frames, which stall when the tab is in the background. An interrupted animation can miss its callback. Our tests caught this early when a link whose fade-in was interrupted stayed invisible. Now a timer sets the final state whether or not the animation finishes.

Elements the host is hiding

If the host application reveals new nodes one at a time, it will have hidden some elements itself. When an update redraws a hidden link, the link has to come back hidden. The update takes a function that identifies which elements the host is holding back. Those elements stay hidden when added or redrawn, ready for the host to show in its own time.

Fitting it into a real product

A demo page is one thing. The canvas in Public Insights is several thousand lines of code, tuned over a long time. The fit deserved as much thought as the engine.

What the canvas labels tell us

On our canvas, most link labels say where the record came from: the companies register, the court service, a planning application. An investigator needs to know the source. But an engine that builds its rows from “who controls whom” gets nothing from a label that says “register data”, and reading it harder would not help.

Every link on the canvas is created by a specific piece of code that already knows what the link is. A table records that relationship using the label and the entity types at each end.

def relation(label, source_type, target_type):
    """What a canvas link is: (category, power, stale), or None if unknown."""
    if "postcode" in (source_type, target_type):
        return ("location", "negligible", False)  # addresses sit in the bottom row
    if label in OWNERSHIP:
        person_is_source = source_type in PEOPLE  # the arrow is ignored where
        return ("control", above(person_is_source), stale)  # the types settle it
    if label in APPOINTMENT:
        return ("role", above(source_type in PEOPLE), stale)
    if label == "member of" and "sports_team" in (source_type, target_type):
        return ("role", above(source_type == "sports_team"), stale)  # club above members
    return None  # not in the table: the engine reads the wording, and it is logged

Anything the table does not know, such as a link a user typed in, falls back to the dictionary and the reader. We log those links so the table can grow.

Some rows capture how we would draw the relationship. A charge holder sits above the company. A club sits above its members. Those are our calls.

Adding a view to the canvas

The safest way into a large existing page is to change as little of it as possible. The hierarchy view adds layout fields to the canvas’s existing nodes and edges. The boxes, labels and dots are added as extras.

Anything that changes or reads the whole chart leaves the view first. Expand a node, merge two entities, save, load or change the type filter, and the view clears itself. The extras vanish, and the rest of the page never meets them. One press of the button brings it back. The total change to the existing page came to about fifteen lines.

Every link gets drawn

A presentation chart can afford to drop a minor link when the line would be awkward. An investigation tool cannot. If the tool found a link, the user sees it. In the hierarchy view every link is drawn, every time.

Feeding the assistant

Our canvas has an AI assistant that investigates from a few starting entities and adds what it finds. The code that reveals its findings is the most carefully tuned part of the page. It adds each batch hidden, arranges the whole chart once, then reveals nodes one at a time where they already sit, at a pace set by how much is queued.

That pattern suits the engine well. The hierarchy view takes over the layout step. Each batch goes to the engine as a change to the existing chart, so it tries to hold the entities already in place. The reveal still waits for the layout to finish. Labels and boxes stay hidden until something they belong to has been revealed.

Tuning the end of a run

Because every decision is recorded and the chart is kept server-side, any run can be replayed through the engine afterwards. We used that to tune the moment an assistant run ends, when duplicates are merged and the chart gets its final tidy.

Replaying a 78-entity chart from a test run showed two refinements worth making.

The first was to keep the look-back out of the final tidy. On that chart:

Final tidy Order kept
With the look-back 51%
Without it 90%

The second was in holding. Creating a new overlap means bringing two boxes side by side, so the engine skips that when it is holding the chart in place. It now preserves the overlaps that already exist. On the replayed chart, removing a single entity used to shift about a third of the others. Now it moves none.

The hierarchy view is now in testing in our development build.

If you are building something similar

A few things we would do again.

Start with rules in the decider’s seat and measure everything against them. You only know a model has earned its place if the rules were there first.

Make every judgement a recorded decision with a confidence score and a reason. It makes the engine debuggable, and it is why a replay takes minutes.

Check your ideas with a blind comparison before you ship them. The chart is for people to read.

Measure movement by how well entities keep their order.

Treat the layout as a view over the host’s data, and leave the view whenever the data changes underneath you.

And do not let a tool for investigators drop a link because the line was awkward.

Similar posts

Get notified about new tools and techniques for OSINT

Learn about new developments in the world of OSINT from the Public Insights team.