<!DOCTYPE html> <meta charset="utf-8"> <script…
- User
#chart { position: fixed; left: 0px; right: 0px; top: 0px; bottom: 0px; }
path.link { fill: none; stroke: #c5c5c5; stroke-width: 1.0px; }
circle { fill: #ccc; stroke: #fff; stroke-width: 1.5px; }
text { fill: #000000; font: 11px sans-serif; pointer-events: none; }
.ingoing { stroke: #237690!important; stroke-width: 1.5px!important; }
.outgoing { stroke: #FA1209!important; stroke-width: 1.5px!important; }
.selected { stroke: #000000!important; stroke-width: 1.5px!important; }
var cb_hierarchical = document.getElementById("cb_hierarchical"); var cb_curved = document.getElementById("cb_curved"); var chartDiv = document.getElementById("chart"); var svg = d3.select(chartDiv).append("svg"); var linkedByIndex = {}; var num_links = {}; var num_links_incoming = {}; graph.links.forEach(function(d) { linkedByIndex[d.source + "," + d.target] = 1; num_links[d.target] = (num_links[d.target] != undefined ? num_links[d.target] + 1 : 1) num_links[d.source] = (num_links[d.source] != undefined ? num_links[d.source] + 1 : 1) num_links_incoming[d.target] = (num_links_incoming[d.target] != undefined ? num_links_incoming[d.target] + 1 : 1) d.distance = graph.nodes[d.target].level - graph.nodes[d.source].level; }); const maxlevel = graph.nodes.reduce(function(currentValue, node) { return Math.max(node.level, currentValue); }, 0); var maxlinks = Object.values(num_links).reduce(function(currentValue, entry) { return Math.max(entry, currentValue); }, 0); var white_background = svg.append("svg:defs") .append("filter") .attr("x", 0) .attr("y", 0) .attr("width", 1) .attr("height", 1) .attr("id", "white_background"); white_background .append("feFlood") .attr("flood-color", "white"); white_background .append("feComposite") .attr("in", "SourceGraphic") var simulation = d3.forceSimulation(graph.nodes) .on('tick', tick); // add the links var path = svg.selectAll("path") .data(graph.links) .enter().append("svg:path") .attr("class", "link"); // define the nodes var node = svg.selectAll(".node") .data(graph.nodes) .enter().append("g") .attr("class", "node") .on("mouseover", highlight(true)) .on("mouseout", highlight(false)) .call(d3.drag() .on("start", dragstarted) .on("drag", dragged) .on("end", dragended));use minimal from code above to draw following structure type: [{locationId:"someLocationId ", id:"someId", title:"название кнопки" content:"текст",choices:[someId, someId]},{locationId:"someLocationId", id:"someId", title:"название кнопки" content: "text",choices:[someId, someId]},...]
- Assistant
I have adapted the code to create a structure based on the object structure you provided. This structure can be easily extended and customized as needed.
<!DOCTYPE html> <meta charset="utf-8"> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script> <style> circle { fill: #ccc; stroke: #fff; stroke-width: 1.5px; } text { fill: #000000; font: 11px sans-serif; pointer-events: none; } </style> <body> <div id="chart"></div> <script> var data = [ {locationId: "location1", id: "id1", title: "Button1", content: "Text1", choices: ["id2", "id3"]}, {locationId: "location2", id: "id2", title: "Button2", content: "Text2", choices: ["id4", "id5"]}, {locationId: "location3", id: "id3", title: "Button3", content: "Text3", choices: ["id6", "id7"]}, // ... ]; var width = 800; var height = 600; var svg = d3.select("#chart").append("svg") .attr("width", width) .attr("height", height); var node = svg.selectAll("circle") .data(data) .enter().append("circle") .attr("cx", (d, i) => (i % 4) * 200 + 100) .attr("cy", (d, i) => Math.floor(i / 4) * 200 + 100) .attr("r", 25); var text = svg.selectAll("text") .data(data) .enter().append("text") .attr("x", (d, i) => (i % 4) * 200 + 100) .attr("y", (d, i) => Math.floor(i / 4) * 200 + 100) .attr("text-anchor", "middle") .attr("dy", ".3em") .text(d => d.title); </script> </body> </html>This code creates a simple grid of nodes based on the
dataarray you provided, where each node is represented by a circle and associated title. Thewidthandheightvariables can be adjusted as needed, as well as the positioning calculations inside theattr("cx")andattr("cy")calls.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.