Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
magicsunday committed Jan 13, 2024
1 parent ca1a520 commit 49136af
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
"d3-fetch": "^3.0.1",
"d3-hierarchy": "^3.1.2",
"d3-path": "^3.1.0",
"d3-scale": "^4.0.2",
"d3-selection": "^3.0.0",
"d3-shape": "^3.2.0",
"d3-timer": "^3.0.1",
"d3-transition": "^3.0.1",
"d3-zoom": "^3.0.0",
"rollup": "^4.5.2"
"rollup": "^4.9.3"
}
}
36 changes: 18 additions & 18 deletions resources/js/modules/custom/hierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,45 +32,45 @@ export default class Hierarchy
/**
* Initialize the hierarchical chart data.
*
* @param {Object} data The JSON encoded chart data
* @param {Object} datum The JSON encoded chart data
*/
init(data)
init(datum)
{
// Get the greatest depth
const getDepth = ({parents}) => 1 + (parents ? Math.max(...parents.map(getDepth)) : 0);
const maxGenerations = getDepth(data);
const maxGenerations = getDepth(datum);

// Construct root node from the hierarchical data
this._root = d3.hierarchy(
data,
data => {
datum,
datum => {
if (!this._configuration.showEmptyBoxes) {
return data.parents;
return datum.parents;
}

// Fill up the missing parents to the requested number of generations
if (!data.parents && (data.data.generation < maxGenerations)) {
// if (!data.parents && (data.data.generation < this._configuration.generations)) {
data.parents = [
this.createEmptyNode(data.data.generation + 1, SEX_MALE),
this.createEmptyNode(data.data.generation + 1, SEX_FEMALE)
if (!datum.parents && (datum.data.generation < maxGenerations)) {
// if (!datum.parents && (datum.data.generation < this._configuration.generations)) {
datum.parents = [
this.createEmptyNode(datum.data.generation + 1, SEX_MALE),
this.createEmptyNode(datum.data.generation + 1, SEX_FEMALE)
];
}

// Add missing parent record if we got only one
if (data.parents && (data.parents.length < 2)) {
if (data.parents[0].sex === SEX_MALE) {
data.parents.push(
this.createEmptyNode(data.data.generation + 1, SEX_FEMALE)
if (datum.parents && (datum.parents.length < 2)) {
if (datum.parents[0].data.sex === SEX_MALE) {
datum.parents.push(
this.createEmptyNode(datum.data.generation + 1, SEX_FEMALE)
);
} else {
data.parents.unshift(
this.createEmptyNode(data.data.generation + 1, SEX_MALE)
datum.parents.unshift(
this.createEmptyNode(data.datum.generation + 1, SEX_MALE)
);
}
}

return data.parents;
return datum.parents;
});

// Assign a unique ID to each node
Expand Down
21 changes: 18 additions & 3 deletions resources/js/modules/lib/d3.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/**
* This file is part of the package magicsunday/webtrees-pedigree-chart.
* This file is part of the package magicsunday/webtrees-fan-chart.
*
* For the full copyright and license information, please read the
* LICENSE file distributed with this source code.
* LICENSE file that was distributed with this source code.
*/

/*
https://github.com/d3/d3-fetch
https://github.com/d3/d3-hierarchy
https://github.com/d3/d3-path
https://github.com/d3/d3-scale
https://github.com/d3/d3-selection
https://github.com/d3/d3-shape
https://github.com/d3/d3-timer
https://github.com/d3/d3-transition
https://github.com/d3/d3-zoom
*/
Expand All @@ -19,17 +22,29 @@ export {
} from "d3-fetch";

export {
Node, hierarchy, tree
Node, hierarchy, partition, tree
} from "d3-hierarchy";

export {
path
} from "d3-path";

export {
scaleLinear
} from "d3-scale";

export {
select, selectAll
} from "d3-selection";

export {
timer
} from "d3-timer";

export {
arc
} from "d3-shape";

export {
transition
} from "d3-transition";
Expand Down
2 changes: 1 addition & 1 deletion resources/js/pedigree-chart.min.js

Large diffs are not rendered by default.

0 comments on commit 49136af

Please sign in to comment.