Skip to content

Commit

Permalink
#9 chore: Add z-index order
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed Aug 1, 2022
1 parent 56e745b commit 83d09a7
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 79 deletions.
13 changes: 10 additions & 3 deletions dist/meta-diagram.cjs.development.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/meta-diagram.cjs.development.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/meta-diagram.cjs.production.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/meta-diagram.cjs.production.min.js.map

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions dist/meta-diagram.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/meta-diagram.esm.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/models/MetaNode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export declare class MetaNode {
getId(): string;
getParentId(): string | undefined;
getWorldPosition(): Position;
private getDepth;
toModel(): MetaNodeModel;
}
4 changes: 1 addition & 3 deletions example/components/widgets/CustomNodeWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class CustomNodeWidget extends React.Component<CustomNodeWidgetProps> {
render() {
// @ts-ignore
const customNodeStyle = {
zIndex: 999999999,
zIndex: Math.pow(10, this.props.model.getOptions()['depth']),
border: "solid 2px gray",
borderRadius: "5px",
width: "250px",
Expand All @@ -23,8 +23,6 @@ export class CustomNodeWidget extends React.Component<CustomNodeWidgetProps> {
justifyContent: "space-between",
position: "relative",
background: this.props.model.getOptions()['color'] || "darkgray",
top: this.props.model.getOptions()['position'].y || 0,
left: this.props.model.getOptions()['position'].x || 0,
}

// console.log("Node Render Position: ")
Expand Down
64 changes: 0 additions & 64 deletions example/components/widgets/DiamondNodeWidget.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion example/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {makeStyles} from "@material-ui/core";
import CustomLinkWidget from "./components/widgets/CustomLinkWidget";
import BG from "./components/assets/svg/bg-dotted.svg";
import {DiamondNodeWidget} from "./components/widgets/DiamondNodeWidget";
import CustomNodeWidget from "./components/widgets/CustomNodeWidget";

const useStyles = makeStyles(_ => ({
main: {
Expand Down Expand Up @@ -37,7 +38,7 @@ const App = () => {
new Map(Object.entries({color: 'rgb(255,192,0)'})))

const componentsMap = new ComponentsMap(
new Map(Object.entries({'default': DiamondNodeWidget})),
new Map(Object.entries({'default': CustomNodeWidget})),
new Map(Object.entries({'default': CustomLinkWidget}))
)

Expand Down
1 change: 1 addition & 0 deletions src/helpers/engineHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export function updateChildrenPosition(nodes: MetaNodeModel[], parent: MetaNodeM

export function updateNodeLocalPosition(nodes: MetaNodeModel[], node: MetaNodeModel): void {
node.updateLocalPosition(nodes)
// TODO: check if it is still inside the parent
}
1 change: 1 addition & 0 deletions src/helpers/nodesHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function getNode(
}

export function processNodes(metaNodes: MetaNode[], callback: { (event: any): void; (arg0: BaseEntityEvent<NodeModel<NodeModelGenerics>>): void; }) : MetaNodeModel[] {
// TODO set z order
const metaNodeModels = []
for(const mn of metaNodes){
const metaNodeModel = mn.toModel()
Expand Down
1 change: 0 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const MetaDiagram = ({
const nodes = model.getNodes()
// @ts-ignore
updateChildrenPosition(nodes, node)
// TODO: FIx nodes drifting away due to the following line
// @ts-ignore
updateNodeLocalPosition(nodes, node)
engine.repaintCanvas();
Expand Down
5 changes: 5 additions & 0 deletions src/models/MetaNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ export class MetaNode {
return this.parent ? this.position.add(this.parent?.getWorldPosition()) : this.position
}

private getDepth() : number {
return this.parent ? this.parent.getDepth()+1 : 0
}

toModel() : MetaNodeModel {
const optionsMap = this.options
optionsMap.set('parentId', this.getParentId())
optionsMap.set('position', this.position)
optionsMap.set('depth', this.getDepth())
return new MetaNodeModel(Object.fromEntries(optionsMap))
}

Expand Down

0 comments on commit 83d09a7

Please sign in to comment.