Skip to content

Commit

Permalink
Resolver/nodedesign 25 (elastic#60630)
Browse files Browse the repository at this point in the history
* PR base

* adds designed resolver nodes

* adjust distance between nodes

* WIP remove stroke

* WIP changes to meet mocks

* new boxes

* remove animation

* new box assets

* baby resolver running nodes complete

* cleanup defs, add running trigger cube

* added 2 more defs for process cubes

* adding switched for assets on node component

* vacuuming defs file

* adjusting types and references to new event model

* switch background to full shade for contrast

* switch background to full shade for contrast

* cube, animation and a11y changes to 25% nodes

* PR base

* adds designed resolver nodes

* adjust distance between nodes

* WIP remove stroke

* WIP changes to meet mocks

* new boxes

* remove animation

* new box assets

* baby resolver running nodes complete

* cleanup defs, add running trigger cube

* added 2 more defs for process cubes

* adding switched for assets on node component

* vacuuming defs file

* adjusting types and references to new event model

* switch background to full shade for contrast

* cube, animation and a11y changes to 25% nodes

* merge upstream

* change from Legacy to new Resolver event

* cleaning up unused styles

* fix adjacency map issues

* fix process type to cube mapping

* fix typing on selctor

* set viewport to strict

* remove unused types

* fixes ci / testing issues

* feedback from Jon Buttner

* fix index from Jon Buttner comment

* reset focus state on nodes

* Robert review: changing adjacency map property names for better semantics

* Robert Austin review: changing var name

* Robert Austin review: rearrange code for readability

* Robert Austin review: change const name

* Robert Austin review: rearranging code for readability

* Robert Austin review: adjustments to process_event_dot

* Robert Austin review: replace level getter

* Robert Austin review: removing unnecessary casting

* Robert Austin review: adjust selector

* Robert Austin review: fix setting parent map

* Robert Austin review: replace function with consts

* K Qualters review: change return type of function

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
bkimmel and elasticmachine authored Mar 23, 2020
1 parent a0a85db commit dd93a14
Show file tree
Hide file tree
Showing 11 changed files with 887 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { uniquePidForProcess, uniqueParentPidForProcess } from './process_event';
import { IndexedProcessTree } from '../types';
import { IndexedProcessTree, AdjacentProcessMap } from '../types';
import { ResolverEvent } from '../../../../common/types';
import { levelOrder as baseLevelOrder } from '../lib/tree_sequencers';

Expand All @@ -15,21 +15,89 @@ import { levelOrder as baseLevelOrder } from '../lib/tree_sequencers';
export function factory(processes: ResolverEvent[]): IndexedProcessTree {
const idToChildren = new Map<string | undefined, ResolverEvent[]>();
const idToValue = new Map<string, ResolverEvent>();
const idToAdjacent = new Map<string, AdjacentProcessMap>();

function emptyAdjacencyMap(id: string): AdjacentProcessMap {
return {
self: id,
parent: null,
firstChild: null,
previousSibling: null,
nextSibling: null,
level: 1,
};
}

const roots: ResolverEvent[] = [];

for (const process of processes) {
idToValue.set(uniquePidForProcess(process), process);
const uniqueProcessPid = uniquePidForProcess(process);
idToValue.set(uniqueProcessPid, process);

const currentProcessAdjacencyMap: AdjacentProcessMap =
idToAdjacent.get(uniqueProcessPid) || emptyAdjacencyMap(uniqueProcessPid);
idToAdjacent.set(uniqueProcessPid, currentProcessAdjacencyMap);

const uniqueParentPid = uniqueParentPidForProcess(process);
const processChildren = idToChildren.get(uniqueParentPid);
if (processChildren) {
processChildren.push(process);
const currentProcessSiblings = idToChildren.get(uniqueParentPid);

if (currentProcessSiblings) {
const previousProcessId = uniquePidForProcess(
currentProcessSiblings[currentProcessSiblings.length - 1]
);
currentProcessSiblings.push(process);
/**
* Update adjacency maps for current and previous entries
*/
idToAdjacent.get(previousProcessId)!.nextSibling = uniqueProcessPid;
currentProcessAdjacencyMap.previousSibling = previousProcessId;
if (uniqueParentPid) {
currentProcessAdjacencyMap.parent = uniqueParentPid;
}
} else {
idToChildren.set(uniqueParentPid, [process]);

if (uniqueParentPid) {
/**
* Get the parent's map, otherwise set an empty one
*/
const parentAdjacencyMap =
idToAdjacent.get(uniqueParentPid) ||
(idToAdjacent.set(uniqueParentPid, emptyAdjacencyMap(uniqueParentPid)),
idToAdjacent.get(uniqueParentPid))!;
// set firstChild for parent
parentAdjacencyMap.firstChild = uniqueProcessPid;
// set parent for current
currentProcessAdjacencyMap.parent = uniqueParentPid || null;
} else {
// In this case (no unique parent id), it must be a root
roots.push(process);
}
}
}

/**
* Scan adjacency maps from the top down and assign levels
*/
function traverseLevels(currentProcessMap: AdjacentProcessMap, level: number = 1): void {
const nextLevel = level + 1;
if (currentProcessMap.nextSibling) {
traverseLevels(idToAdjacent.get(currentProcessMap.nextSibling)!, level);
}
if (currentProcessMap.firstChild) {
traverseLevels(idToAdjacent.get(currentProcessMap.firstChild)!, nextLevel);
}
currentProcessMap.level = level;
}

for (const treeRoot of roots) {
traverseLevels(idToAdjacent.get(uniquePidForProcess(treeRoot))!);
}

return {
idToChildren,
idToProcess: idToValue,
idToAdjacent,
};
}

Expand All @@ -38,8 +106,8 @@ export function factory(processes: ResolverEvent[]): IndexedProcessTree {
*/
export function children(tree: IndexedProcessTree, process: ResolverEvent): ResolverEvent[] {
const id = uniquePidForProcess(process);
const processChildren = tree.idToChildren.get(id);
return processChildren === undefined ? [] : processChildren;
const currentProcessSiblings = tree.idToChildren.get(id);
return currentProcessSiblings === undefined ? [] : currentProcessSiblings;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,23 @@ interface UserChangedSelectedEvent {
interface AppRequestedResolverData {
readonly type: 'appRequestedResolverData';
}
/**
* When the user switches the active descendent of the Resolver.
*/
interface UserFocusedOnResolverNode {
readonly type: 'userFocusedOnResolverNode';
readonly payload: {
/**
* Used to identify the process node that should be brought into view.
*/
readonly nodeId: string;
};
}

export type ResolverAction =
| CameraAction
| DataAction
| UserBroughtProcessIntoView
| UserChangedSelectedEvent
| AppRequestedResolverData;
| AppRequestedResolverData
| UserFocusedOnResolverNode;
Loading

0 comments on commit dd93a14

Please sign in to comment.