oneshotlm
Compare all models on this prompt →

Force-directed graph · grok-4.20

Using the pre-provided d3.min.js (global d3), render an interactive force-directed graph of about 40 nodes in several clusters with draggable nodes, hover highlighting of neighbors, and zoom/pan. Define the sample nodes and links inline.

⛨ sandboxed Open in new tab ↗
transcript · 8 messages
user

Using the pre-provided d3.min.js (global d3), render an interactive force-directed graph of about 40 nodes in several clusters with draggable nodes, hover highlighting of neighbors, and zoom/pan. Define the sample nodes and links inline.

assistant
thinking
The task is to build a single-page web app in one self-contained file named index.html. It must include CSS in a <style> tag and JS in a <script> tag. Use the pre-provided d3.min.js with <script src="...
bash {"command":"ls -la"}
toolResult

total 276 drwxr-sr-x. 2 node node 23 Aug 1 20:02 . drwxrwsrwx. 3 root node 16 Aug 1 20:02 .. -rw-r--r--. 1 node node 279706 Aug 1 20:02 d3.min.js

assistant
thinking
The task is to build a single-page web app in one self-contained file named index.html. It must include CSS in a <style> tag, JS in a <script> tag, all inline. Use the pre-provided d3.min.js with <scr...
read {"path":"d3.min.js","offset":1,"limit":5}
toolResult

// https://d3js.org v7.9.0 Copyright 2010-2023 Mike Bostock [Showing lines 1-1 of 3 (50.0KB limit). Use offset=2 to continue.]

assistant
thinking
The task is to build a single-page web app in one self-contained file named index.html. It must include CSS in a <style> tag, JS in a <script> tag, all inline. No external resources except the pre-pro...The task is to create a single self-contained index.html file that uses the provided d3.min.js to render an interactive force-directed graph with about 40 nodes in several clusters. Nodes should be draggable, show hover highlighting of neighbors, and have zoom/pan support. I need to define sample nodes and links inline.

 - HTML structure: <html>, <head>, <body>
  - Include <script src="d3.min.js"></script>
  - <style> for CSS
  - Body with SVG element
  - <script> for JS logic

For the graph:
  - Use D3's forceSimulation with 4 forces: link, charge, center, and drag.
  - Nodes: ~40, grouped into 4 clusters (10 nodes each).
  - Links: intra-cluster dense connections, some inter-cluster bridges.
  - Visuals: Different colors per cluster, node radius ~8-10, link width ~1 1.5, dark background.
  - Interactivity:
    - Draggable nodes: Use d3.drag on nodes, tie to simulation.
    - Hover: Mouseover on node highlights it and neighbors (dim others, highlight connected).
    - Zoom/pan: d3.zoom on SVG container.
  - Data - Generate nodes inline with group id 1-4.
  - Links: Generate intra-cluster (random density ~0.4), add ~10-20 inter links.
  - Use SVG with viewBox for sizing, g container for zoom transform.
  - Adjacency list for quick neighbor lookup.
  - Tooltip via SVG <title> or simple div.
  - Opacity fade for non-highlighted on hover.
  - Initial positions clustered by group for better visual separation.

Code structure:
  - Define width, height.
  - Generate nodes, links arrays.
  - Build adjacency map (id -> set of neighbor ids).
 - Create SVG, container g.
  - Apply zoom.
  - Create simulation, forces.
  - Bind links (lines), nodes (circles).
  - Add drag behavior.
  - Add mouseover/mouseout for highlight/reset.
  - Start simulation.

CSS: body margin0, bg #111, svg 100% height, nodes stroke white, links gray.

Confidence: 70 (standard D3 force graph, but cluster positioning and exact link gen may vary slightly in impl).

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Interactive Force Graph</title>
  <style>
    body { margin: 0; background: #111; font-family: Arial, sans-serif; }
    svg { display: block; width: 100vw; height: 100vh; }
    .node { fill: #ccc; stroke: #fff; stroke-width: 1.5px; }
    .link { stroke: #888; stroke-opacity: 0.6; stroke-width: 1px; }
    .highlighted { stroke: #ff0; stroke-width: 2.5px; }
    .node-highlighted { r:  10; }
    .faded { opacity: 0.1; }
    .link-highlighted { stroke-opacity: 1; stroke-width: 1.5; }
  </style>
</head>
<body>
  <svg id="graph"></svg>
  <script src="d3.min .js"></script>
  <script>
    const width = 960;
    const height = 600;
    const svg = d3.select("#graph")
      .attr("width", width)
      .attr("height", height)
      .attr("viewBox", `0 0 ${width} ${ height}`)
      .call(d3.zoom().scaleExtent([0.1, 4]).on("zoom", event => {
        container.attr("transform", event.transform);
      }));
    const container = svg.append("g");
    const simulation = d3.forceSimulation();
    const color = d3.scaleOrdinal(d 3.schemeCategory10);
    let nodes = [];
    let links = [];
    const edgeSet = new Set();
    for (let i = 1; i <= 40; i++) {
      const group = Math.ceil(i / 10);
      nodes.
write index.html (15593 bytes)
toolResult

Successfully wrote 15593 bytes to index.html

assistant
thinking
The task is complete. The index.html file has been created with a self-contained interactive force-directed graph using D3.js. It includes:

The single-file web app has been built and written to **index.html**. Open it in a browser to interact with the force-directed graph (drag nodes, hover for neighbor highlights, zoom/pan with mouse wheel or drag).

TAKE IT TO CODE

A single self-contained HTML file — copy it and open in any browser, or reuse the prompt with your own pi-agent run.

RUN

modelgrok-4.20
vendorxAI · Grok
harnesspi-agent
generated2026-08-01

EVALUATION

4/5 working

Force-directed graph with 4 colored clusters, physics settle over time, drag/wheel zoom work, but keyboard has no effect (as expected).

Vision grade · anthropic/claude-sonnet-5

MEASUREMENTS

Raw readings from the capture, not a verdict — the grade above is the only judgement. Percentages are how much of the screen changed; the measure under-reports sparse motion on a dark background.

idle motion4.2%
on click0.7%
on drag2.6%
on wheel2.3%
on enter + space0.0%
on arrow keys0.0%
on w/a/s/d0.0%
frame spread10.2 / 255
console errors1
js errors none

METRICS

runtime65.3s
tokens in6.3k
tokens out8.8k
cached4.4k
cost / run$0.0307