Skip to content

Commit

Permalink
Merge branch 'code-graph-layout-redo'
Browse files Browse the repository at this point in the history
  • Loading branch information
phfaist committed Mar 22, 2024
2 parents bb11d01 + cd00722 commit cc12577
Show file tree
Hide file tree
Showing 40 changed files with 3,355 additions and 2,406 deletions.
2 changes: 1 addition & 1 deletion _zoodb_citations_cache/cache_compiled_citations.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _zoodb_citations_cache/cache_downloaded_info.json

Large diffs are not rendered by default.

80 changes: 66 additions & 14 deletions eczoodb/eczoodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,6 @@ export class EcZooDb extends ZooDb
}
}
return false;
// ### Nope, don't explore cousin relationships recursively!! Single
// ### level only.
//
// let result = false;
// this.code_visit_relations(code, {
// relation_properties: ['cousins', 'cousin_of'],
// callback: (code) => {
// if (code.code_id === cousin_code_id) {
// result = true;
// return true;
// }
// },
// });
// return result;
}

code_parent_domains(code, { find_domain_id, only_primary_parent_relation } = {})
Expand Down Expand Up @@ -319,6 +305,70 @@ export class EcZooDb extends ZooDb
return family_tree_codes;
}

/**
* Follows primary-parent relationships upwards as long as possible. When
* no further primary-parent is found (e.g., for a root property code or for
* a kingdom root code), then information about that code is returned.
*
* Returns an object
* `{ primary_parent_root_code, primary_parent_chain_code_ids }`
* containing the root code object and the chain of `code_id`'s explored until
* we reached the root code.
*/
code_get_primary_parent_root(code)
{
// Primary parent relationship = first parent in the parents: list, except for kingdom
// root codes (in which case the kingdom node is the 'primary parent') (?)

// follow primary parent relationship to determine a root code
// whether we're part of a kingdom.
let primary_parent_root_code = code;
// detect any cycles so we can report an error.
let primary_parent_chain_code_ids = [ code.code_id ];
while ( (primary_parent_root_code.relations?.root_for_kingdom == null
|| primary_parent_root_code.relations?.root_for_kingdom?.length == 0)
&& primary_parent_root_code.relations?.parents?.length > 0 ) {
primary_parent_root_code = primary_parent_root_code.relations.parents[0].code;
const primary_parent_root_code_id = primary_parent_root_code.code_id;
if (primary_parent_chain_code_ids.includes(primary_parent_root_code_id)) {
const seenCodeChainNames = [].concat(
primary_parent_chain_code_ids,
[ primary_parent_root_code_id ]
).map( (cId) => {
let c = this.objects.code[cId];
return `‘${c.name.flm_text ?? c.name}’ (${c.code_id})`;
} );
throw new Error(
`Detected cycle in primary-parent relationships: `
+ seenCodeChainNames.join(' → ')
);
} else {
primary_parent_chain_code_ids.push( primary_parent_root_code_id );
}
}
return { primary_parent_root_code, primary_parent_chain_code_ids };
}

code_get_parent_kingdom(code, { primary_parent_root_code }={})
{
if (primary_parent_root_code == null) {
({ primary_parent_root_code } = this.code_get_primary_parent_root(code));
}

let root_for_kingdom = primary_parent_root_code.relations?.root_for_kingdom;
if (root_for_kingdom == null || root_for_kingdom.length === 0) {
return null;
}

if (root_for_kingdom.length > 1) {
throw new Error(
`Code ${primary_parent_root_code.code_id} is a root code for multiple kingdoms: `
+ root_for_kingdom.map((k) => k.kingdom_id).join(', ')
);
}

return root_for_kingdom[0].kingdom;
}

/**
* Sort the given list of objects such that parents always appear before any
Expand Down Expand Up @@ -465,6 +515,8 @@ export class EcZooDb extends ZooDb
}




//
// Validate the database. Enforces any external constraints (e.g. no cycles
// in the parent-child relationship).
Expand Down
9 changes: 9 additions & 0 deletions jscomponents/.parcelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "@parcel/config-default",

"resolvers": [
"@mischnic/parcel-resolver-root",
"...",
],

}
10 changes: 5 additions & 5 deletions jscomponents/codegraph/CodeGraphInformationPane.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ function renderHtmlKingdom({ eczoodb, kingdom, captureLinksToObjectTypes, })

function renderHtmlEmpty({ eczoodb, captureLinksToObjectTypes, })
{
const { flm_simple_content, render } = mkRenderWrapUtils({
const { flm_simple_content_, render } = mkRenderWrapUtils({
eczoodb,
captureLinksToObjectTypes,
});
Expand All @@ -358,7 +358,7 @@ function renderHtmlEmpty({ eczoodb, captureLinksToObjectTypes, })
<p style="margin-top: 2em">Zoom into:</p>
<ul>`;

for (const [domain_id, domain] of Object.entries(eczoodb.objects.domain)) {
for (const [domain_id, domain_] of Object.entries(eczoodb.objects.domain)) {
s += sqzhtml`
<li>${ ref('domain', domain_id) }</li>`;
}
Expand Down Expand Up @@ -400,7 +400,7 @@ export function CodeGraphInformationPane(props)
displayInformationOptions,
} = props;

debug(`In CodeGraphInformationPane ()`, props);
debug(`CodeGraphInformationPane component - render`, props);

captureLinksToObjectTypes ??= [ 'code', 'domain', 'kingdom' ];

Expand Down Expand Up @@ -459,7 +459,7 @@ export function CodeGraphInformationPane(props)
let domNode = contentDomRef.current;
if (domNode != null) {
// install MathJax formulas
if (window.MathJax != null) {
if (window?.MathJax?.typesetPromise != null) {
await window.MathJax.typesetPromise([ domNode ]);
}
// install link callbacks
Expand All @@ -485,7 +485,7 @@ export function CodeGraphInformationPane(props)
};
setupHtmlContent();
return;
}, [compiledHtmlContent, currentCodeSelected, currentDomainSelected, currentKingdomSelected] );
} );

return (
<div className="CodeGraphInformationPane"
Expand Down
Loading

0 comments on commit cc12577

Please sign in to comment.