Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stratify for faster hierarchy builds #6506

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions waltz-ng/client/common/hierarchy-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
*/
import _ from "lodash";
import {stratify} from "d3";


/**
Expand Down Expand Up @@ -131,6 +132,24 @@ export function buildHierarchies(nodes, parentsAsRefs = true) {
return _.reject(populateParents(nodes, parentsAsRefs), n => n.parent);
}

export function buildHierarchies2(nodes) {

console.time("stratify");
const withRoot = _.concat([{id: -99}], nodes || []);
console.log({nodes, withRoot})
const sr = stratify()
.parentId(d => d.id === -99
? null
: d.parentId ?? -99)
(withRoot);
const forest = _.map(sr.children, c => Object.assign(c, {parentId: null, parent: null}));
console.timeEnd("stratify");
console.log({forest})
return forest;
// return [sr];

}

export const reduceToSelectedNodesOnly = (nodes, selectedNodeIds = []) => {
const byId = _.keyBy(nodes, d => d.id);
const selectedNodesOnly = _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
tree-model="$ctrl.hierarchy"
options="$ctrl.treeOptions"
expanded-nodes="$ctrl.expandedNodes"
order-by="'-name'">
<span ng-class="{ 'text-muted': node.rating == null }"
order-by="'-data.name'">
<span ng-class="{ 'text-muted': node.data.rating == null }"
class="no-overflow">
<span ng-if="$ctrl.onSelect"
class="clickable"
ng-click="$ctrl.onSelect(node)">
ng-click="$ctrl.onSelect(node.data)">
<span ng-include="'wmt/measurable-node.html'"></span>
</span>
<a ng-if="!$ctrl.onSelect"
Expand All @@ -70,7 +70,7 @@
'wmt-measurable-removed': node.entityLifecycleStatus === 'REMOVED',
'wmt-measurable-pending': node.entityLifecycleStatus === 'PENDING'
}">
<waltz-entity-icon-label entity-ref="node"
<waltz-entity-icon-label entity-ref="node.data"
additional-display-data="[ { name: 'Number of apps', value: node.totalCount }]"
icon-placement="none"
tooltip-placement="right">
Expand Down
6 changes: 4 additions & 2 deletions waltz-ng/client/measurable/components/tree/measurable-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import {
doSearch,
prepareSearchNodes,
determineExpandedNodes,
determineDepthLimit} from "../../../common/hierarchy-utils";
determineDepthLimit,
buildHierarchies2
} from "../../../common/hierarchy-utils";
import template from "./measurable-tree.html";


Expand Down Expand Up @@ -76,7 +78,7 @@ const recursivelySum = buildPropertySummer();


function prepareTree(measurables = []) {
const hierarchy = buildHierarchies(measurables, false);
const hierarchy = buildHierarchies2(measurables, false);
_.each(hierarchy, root => recursivelySum(root));
return hierarchy;
}
Expand Down