diff --git a/Sources/Grape/Grape.docc/CreatingAForceDirectedGraph.md b/Sources/Grape/Grape.docc/CreatingAForceDirectedGraph.md new file mode 100644 index 0000000..526d382 --- /dev/null +++ b/Sources/Grape/Grape.docc/CreatingAForceDirectedGraph.md @@ -0,0 +1,3 @@ +# Creating a Force Directed Graph + +## Overview \ No newline at end of file diff --git a/Sources/Grape/Grape.docc/CreatingASimulationWithBuiltinForces.md b/Sources/Grape/Grape.docc/CreatingASimulationWithBuiltinForces.md deleted file mode 100644 index fe98652..0000000 --- a/Sources/Grape/Grape.docc/CreatingASimulationWithBuiltinForces.md +++ /dev/null @@ -1,70 +0,0 @@ -# Creating a Simulation with Built-in Forces - - - -## Overview - - - -You can simply create simulations by using Simulation like this: - -```swift -import simd -import ForceSimulation - -// assuming you’re simulating 4 nodes -let nodeCount = 4 - -// Connect them -let links = [(0, 1), (1, 2), (2, 3), (3, 0)] - -/// Create a 2D force composited with 4 primitive forces. -let myForce = SealedForce2D { - // Forces are namespaced under `Kinetics` - // here we only use `Kinetics>`, i.e. `Kinetics2D` - Kinetics2D.ManyBodyForce(strength: -30) - Kinetics2D.LinkForce( - stiffness: .weightedByDegree(k: { _, _ in 1.0 }), - originalLength: .constant(35) - ) - Kinetics2D.CenterForce(center: .zero, strength: 1) - Kinetics2D.CollideForce(radius: .constant(3)) -} - -/// Create a simulation, the dimension is inferred from the force. -let mySimulation = Simulation( - nodeCount: nodeCount, - links: links.map { EdgeID(source: $0.0, target: $0.1) }, - forceField: myForce -) - -/// Force is ready to start! run `tick` to iterate the simulation. - -for mySimulation in 0..<120 { - mySimulation.tick() - let positions = mySimulation.kinetics.position.asArray() - /// Do something with the positions. -} -``` - -ForceSimulation module mainly contains 3 concepts, `Kinetics`, `ForceProtocol` and `Simulation`. - -@Image(source: "SimulationDiagram.svg", alt: "A diagram showing the relationships of `Kinetics`, `ForceProtocol` and `Simulation`. A `Simulation` contains a `Kinetics` and a `ForceProtocol`.") - -A diagram showing the relationships of `Kinetics`, `ForceProtocol` and `Simulation`. A `Simulation` contains a `Kinetics` and a `ForceProtocol`. - -- `Kinetics` describes all kinetic states of your system, i.e. position, velocity, link connections, and the variable alpha that describes how "active" your system is. `Vector` tells simulation how you decribe a coordinate in this space, it can be `SIMD2` or `SIMD3` or any other types conforming to `SimulatableVector`. - -- Forces are any types that conforms to `ForceProtocol`. This module provides most of the forces you will use in force directed graphs. And you can also create your own forces. They should be responsible for 2 tasks: - - - `bindKinetics(_ kinetics: Kinetics)`: binding to a Kinetics. In most cases the force should keep a reference of the Kinetics so they know what to mutate when apply is called. - - - `apply()`: Mutating the states of Kinetics. For example, a gravity force should add velocities on each node in this function. - -- Simulation is a shell class you interact with, which enables you to create any dimensional simulation with velocity Verlet integration. It manages a Kinetics and a force conforming to ``ForceProtocol``. Since Simulation only stores one force, you are responsible for compositing multiple forces into one. - -- Another data structure ``KDTree`` is used to accelerate the force simulation with Barnes-Hut Approximation. - -In this example, we run our simulation in a 2D space (`SIMD2`). We explicitly create a ``SealedForce2D`` to make sure the force is in the same dimension as the Kinetics. The `Vector` in `Simulation` is inferred from the force we pass. - -See [Examples](https://github.com/li3zhen1/Grape/tree/main/Examples) for example Xcode projects. \ No newline at end of file diff --git a/Sources/Grape/Grape.docc/CustomizingAppearances.md b/Sources/Grape/Grape.docc/CustomizingAppearances.md new file mode 100644 index 0000000..6ef0dee --- /dev/null +++ b/Sources/Grape/Grape.docc/CustomizingAppearances.md @@ -0,0 +1 @@ +# Customizing Appearances diff --git a/Sources/Grape/Grape.docc/DescribingForces.md b/Sources/Grape/Grape.docc/DescribingForces.md new file mode 100644 index 0000000..0d34dc2 --- /dev/null +++ b/Sources/Grape/Grape.docc/DescribingForces.md @@ -0,0 +1,6 @@ +# Describing Forces + + + +## Overview + diff --git a/Sources/Grape/Grape.docc/Documentation.md b/Sources/Grape/Grape.docc/Documentation.md index 6be74ef..b4c8864 100644 --- a/Sources/Grape/Grape.docc/Documentation.md +++ b/Sources/Grape/Grape.docc/Documentation.md @@ -13,9 +13,16 @@ If you’re looking for a more detailed control of force-directed laouts, please ### Creating a graph visualization + +* +* +* +* + * ``ForceDirectedGraph`` + ### Describing a graph * ``GraphContent`` * ``NodeMark`` diff --git a/Sources/Grape/Grape.docc/RespondingToInteractionsAndEvents.md b/Sources/Grape/Grape.docc/RespondingToInteractionsAndEvents.md new file mode 100644 index 0000000..1a4020c --- /dev/null +++ b/Sources/Grape/Grape.docc/RespondingToInteractionsAndEvents.md @@ -0,0 +1 @@ +# Responding to Interactions and Events