|
@ -1,7 +1,13 @@ |
|
|
<script type="ts"> |
|
|
<script type="ts"> |
|
|
|
|
|
import GraphNode from "./GraphNode.svelte"; |
|
|
import { onMount } from "svelte"; |
|
|
import { onMount } from "svelte"; |
|
|
import * as d3 from "d3"; |
|
|
import * as d3 from "d3"; |
|
|
import * as tasksLoader from "./task-loader"; |
|
|
import { createLinksFromTaskMap } from "./task-loader"; |
|
|
|
|
|
import type { TasksFile } from "./task-loader"; |
|
|
|
|
|
|
|
|
|
|
|
export let tasks: TasksFile; |
|
|
|
|
|
let nodes = tasks.tasks; |
|
|
|
|
|
let edges = createLinksFromTaskMap(tasks); |
|
|
|
|
|
|
|
|
// Svelte automatically fills this with a reference |
|
|
// Svelte automatically fills this with a reference |
|
|
let container: HTMLElement; |
|
|
let container: HTMLElement; |
|
@ -12,20 +18,16 @@ |
|
|
width = container.clientWidth - margin.left - margin.right, |
|
|
width = container.clientWidth - margin.left - margin.right, |
|
|
height = container.clientHeight - margin.top - margin.bottom; |
|
|
height = container.clientHeight - margin.top - margin.bottom; |
|
|
|
|
|
|
|
|
// append the svg object to the body of the page |
|
|
// resize the svg object |
|
|
var svg = d3 |
|
|
var svg = d3 |
|
|
.select(container) |
|
|
.select(container) |
|
|
.append("svg") |
|
|
.select("svg") |
|
|
.attr("width", width + margin.left + margin.right) |
|
|
.attr("width", width + margin.left + margin.right) |
|
|
.attr("height", height + margin.top + margin.bottom) |
|
|
.attr("height", height + margin.top + margin.bottom) |
|
|
.attr("viewBox", [-width / 2, -height / 2, width, height]) |
|
|
.attr("viewBox", [-width / 2, -height / 2, width, height]) |
|
|
.append("g") |
|
|
.select("g") |
|
|
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); |
|
|
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); |
|
|
|
|
|
|
|
|
const tasks = await tasksLoader.loadTasks(); |
|
|
|
|
|
let nodes = tasks.tasks; |
|
|
|
|
|
let edges = tasksLoader.createLinksFromTaskMap(tasks); |
|
|
|
|
|
|
|
|
|
|
|
// Initialize the links |
|
|
// Initialize the links |
|
|
var link = svg |
|
|
var link = svg |
|
|
.selectAll("line") |
|
|
.selectAll("line") |
|
@ -34,14 +36,13 @@ |
|
|
.append("line") |
|
|
.append("line") |
|
|
.style("stroke", "#aaa"); |
|
|
.style("stroke", "#aaa"); |
|
|
|
|
|
|
|
|
// Initialize the nodes |
|
|
/*var node = svg |
|
|
var node = svg |
|
|
.selectAll("g") |
|
|
.selectAll("circle") |
|
|
|
|
|
.data(nodes) |
|
|
.data(nodes) |
|
|
.enter() |
|
|
.enter() |
|
|
.append("circle") |
|
|
.append("circle") |
|
|
.attr("r", 20) |
|
|
.attr("r", 20) |
|
|
.style("fill", "#69b3a2"); |
|
|
.style("fill", "#69b3a2");*/ |
|
|
|
|
|
|
|
|
// Let's list the force we wanna apply on the network |
|
|
// Let's list the force we wanna apply on the network |
|
|
var simulation = d3 |
|
|
var simulation = d3 |
|
@ -56,8 +57,8 @@ |
|
|
.links(edges) // and this the list of links |
|
|
.links(edges) // and this the list of links |
|
|
) |
|
|
) |
|
|
.force("charge", d3.forceManyBody().strength(-400)) // This adds repulsion between nodes. Play with the -400 for the repulsion strength |
|
|
.force("charge", d3.forceManyBody().strength(-400)) // This adds repulsion between nodes. Play with the -400 for the repulsion strength |
|
|
.force('x', d3.forceX()) // attracts elements to the zero X coord |
|
|
.force("x", d3.forceX()) // attracts elements to the zero X coord |
|
|
.force('y', d3.forceY()) // attracts elements to the zero Y coord |
|
|
.force("y", d3.forceY()) // attracts elements to the zero Y coord |
|
|
.on("tick", ticked) |
|
|
.on("tick", ticked) |
|
|
.on("end", ticked); |
|
|
.on("end", ticked); |
|
|
|
|
|
|
|
@ -77,13 +78,7 @@ |
|
|
return d.target.y; |
|
|
return d.target.y; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
node |
|
|
nodes = nodes; |
|
|
.attr("cx", function (d) { |
|
|
|
|
|
return d.x + 6; |
|
|
|
|
|
}) |
|
|
|
|
|
.attr("cy", function (d) { |
|
|
|
|
|
return d.y - 6; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
</script> |
|
|
</script> |
|
@ -95,4 +90,12 @@ |
|
|
} |
|
|
} |
|
|
</style> |
|
|
</style> |
|
|
|
|
|
|
|
|
<div bind:this={container} /> |
|
|
<div bind:this={container}> |
|
|
|
|
|
<svg> |
|
|
|
|
|
<g> |
|
|
|
|
|
{#each nodes as task} |
|
|
|
|
|
<GraphNode {task} /> |
|
|
|
|
|
{/each} |
|
|
|
|
|
</g> |
|
|
|
|
|
</svg> |
|
|
|
|
|
</div> |
|
|