Skip to content

Commit

Permalink
chore: commit changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoiver committed Aug 16, 2023
1 parent 5807129 commit 8c8a272
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-ties-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@antv/g-gesture': patch
---

Revert gesture.
159 changes: 159 additions & 0 deletions packages/g-lite/src/components/hierarchy/Hierarchy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { Types, defineComponent } from 'bitecs';

export const HIERARCHY = {
/**
* The ID of the World entity the owner of this component belongs to
*/
WORLD: 0,
/**
* The ID of the Parent entity. If it has no parent, will match the world ID
*/
PARENT: 1,
/**
* The ID of the next entity in the display list (horizontally, the next sibling)
*/
NEXT: 2,
/**
* The ID of the previous entity in the display list (horizontally, the previous sibling)
*/
PREV: 3,
/**
* The ID of the left-most (first) child entity of this parent
*/
FIRST: 4,
/**
* The ID of the right-most (last) child entity of this parent
*/
LAST: 5,
/**
* The number of direct descendants this entity has
*/
NUM_CHILDREN: 6,
/**
* Reserved to allow for per-child depth sorting outside of the display list index
*/
DEPTH: 7,
};

export const HierarchyComponent = defineComponent({
data: [Types.ui32, 8],
});

export function getParentID(id: number): number {
return HierarchyComponent.data[id][HIERARCHY.PARENT];
}

export function getFirstChildID(parentID: number): number {
return HierarchyComponent.data[parentID][HIERARCHY.FIRST];
}

export function getLastChildID(parentID: number): number {
return HierarchyComponent.data[parentID][HIERARCHY.LAST];
}

export function getPreviousSiblingID(id: number): number {
return HierarchyComponent.data[id][HIERARCHY.PREV];
}

export function getNextSiblingID(id: number): number {
return HierarchyComponent.data[id][HIERARCHY.NEXT];
}

export function clearHierarchyComponent(id: number): void {
HierarchyComponent.data[id].fill(0);
}

export function setFirstChildID(parentID: number, childID: number): void {
HierarchyComponent.data[parentID][HIERARCHY.FIRST] = childID;
}

export function setLastChildID(parentID: number, childID: number): void {
HierarchyComponent.data[parentID][HIERARCHY.LAST] = childID;
}

export function setNextSiblingID(parentID: number, childID: number): void {
HierarchyComponent.data[parentID][HIERARCHY.NEXT] = childID;
}

export function setPreviousSiblingID(parentID: number, childID: number): void {
HierarchyComponent.data[parentID][HIERARCHY.PREV] = childID;
}

export function getParents(id: number): number[] {
const results = [];

let currentParent = getParentID(id);

while (currentParent) {
results.push(currentParent);
currentParent = getParentID(currentParent);
}

return results;
}

export function clearSiblings(id: number): void {
setNextSiblingID(id, 0);
setPreviousSiblingID(id, 0);
}

export function linkSiblings(childA: number, childB: number): void {
setNextSiblingID(childA, childB);
setPreviousSiblingID(childB, childA);
}

export function addChildIDAfter(afterID: number, childID: number): void {
const nextID = getNextSiblingID(afterID);

if (nextID) {
linkSiblings(childID, nextID);
} else {
// childID is going to the end of the list
setNextSiblingID(childID, 0);

const parentID = getParentID(childID);

setLastChildID(parentID, childID);
}

linkSiblings(afterID, childID);
}

export function addChildIDBefore(beforeID: number, childID: number): void {
const prevID = getPreviousSiblingID(beforeID);

if (prevID) {
linkSiblings(prevID, childID);
} else {
// childID is going to the start of the list
setPreviousSiblingID(childID, 0);

const parentID = getParentID(childID);

setFirstChildID(parentID, childID);
}

linkSiblings(childID, beforeID);
}

export function removeChildID(childID: number): void {
const parentID = getParentID(childID);

const first = getFirstChildID(parentID);
const last = getLastChildID(parentID);

const prevID = getPreviousSiblingID(childID);
const nextID = getNextSiblingID(childID);

linkSiblings(prevID, nextID);

if (first === childID) {
setFirstChildID(parentID, nextID);
}

if (last === childID) {
setLastChildID(parentID, prevID);
}

clearSiblings(childID);
}

0 comments on commit 8c8a272

Please sign in to comment.