Last active
February 4, 2025 13:02
-
-
Save 62mkv/abb81486bdf2a0c1ac0fa4529a3b7d5b to your computer and use it in GitHub Desktop.
Freeplane Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import necessary Freeplane and Java classes | |
import org.freeplane.plugin.script.proxy.Proxy | |
import org.freeplane.plugin.script.proxy.Proxy.Node | |
import java.awt.Color | |
// Function to get all leaf nodes in natural order | |
def getAllLeafNodes(Node node, List<Node> leaves = []) { | |
if (node.children.size() == 0) { | |
leaves << node | |
} else { | |
leaves << node | |
node.children.each { child -> | |
getAllLeafNodes(child, leaves) | |
} | |
} | |
return leaves | |
} | |
// Function to color all connectors red | |
def colorAllConnectorsRed(Node node, List<Node> leaves) { | |
//println(leaves) | |
// Create a map to store the order of leaf nodes | |
def leafOrder = [:] | |
leaves.eachWithIndex { leaf, index -> | |
leafOrder[leaf] = index | |
} | |
// Check if the node has connectors | |
if (node.connectorsOut) { | |
// Set the color for each connector to red | |
node.connectorsOut.each { connector -> | |
{ | |
def sourceOrder = leafOrder[connector.source] | |
def targetOrder = leafOrder[connector.target] | |
println("Source order: ${sourceOrder}, target order: ${targetOrder}") | |
if (sourceOrder > targetOrder) { | |
connector.color = new Color(255, 0, 0) // Red color in RGB | |
} else { | |
connector.color = new Color(0, 0, 0) // Black color in RGB | |
} | |
} | |
} | |
} | |
// Recursively call the function for each child node | |
node.children.each { child -> | |
colorAllConnectorsRed(child, leaves) | |
} | |
} | |
// Get the current mind map root node | |
def root = node.map.root | |
def leaves = getAllLeafNodes(root) | |
// Call the function to color connectors red | |
// Looks like you can't refer in a `def` function to a variable defined in script "global" space so we have to pass `leaves` as an argument every time | |
colorAllConnectorsRed(root, leaves) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment