BenPortner / js_family_tree

An interactive family tree visualization using d3-dag
GNU General Public License v3.0
75 stars 30 forks source link

Keeping Family Close #18

Open bienieck opened 3 weeks ago

bienieck commented 3 weeks ago

I am creating my family tree based on this project. At the moment everything looks elegant, except for one thing. The parent nodes are separated by other family members (this is shown in the screenshot, pay special attention to partners marked in red). How can I make sure that the closest family members are actually placed next to each other in the graph? seperated-partners

PS In my project, I create links using the following PowerShell script. I think it's much easier and faster.

$filepath = "C:\other\genealogy\js_family_tree\data\data.js"

# Loading file content
$content = Get-Content -Path $filepath -Raw

# Removing the "data=" variable declaration and the semicolon at the end
$content = $content -replace "^data\s*=\s*", ""  # Removes "data=" from beginning
$content = $content -replace ";$", ""            # Removes the semicolon at the end

# Trying to convert to JSON
try {
    $data = $content | ConvertFrom-Json
    Write-Output "Conversion to JSON completed successfully."
} catch {
    Write-Output "Error: Failed to convert data from file to JSON format."
    exit
}

# List where we will save the resulting links structure as arrays of pairs
$links = @()

# Processing persons structure
foreach ($personId in $data.persons.PSObject.Properties.Name) {
    $person = $data.persons.$personId

    # Creating person-union pairs
    if ($person.own_unions) {
        foreach ($unionId in $person.own_unions) {
            $links += ,@($personId, $unionId)  # Adding a pair as an array
        }
    }
}

# Processing unions structure
foreach ($unionId in $data.unions.PSObject.Properties.Name) {
    $union = $data.unions.$unionId

    # Creating union-children pairs
    if ($union.children) {
        foreach ($childId in $union.children) {
            $links += ,@($unionId, $childId)  # Adding a pair as an array
        }
    }
}

# Building a JSON structure with the "links" property
$jsonOutput = @{ links = $links } | ConvertTo-Json -Depth 10

# Displaying the result in PowerShell
Write-Output $jsonOutput

# Saving the resulting links structure to a new file
$linksFilePath = "C:\other\genealogy\js_family_tree\data\links.json"
$jsonOutput | Out-File -FilePath $linksFilePath -Encoding UTF8