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

Release #1492

Merged
merged 3 commits into from
Aug 16, 2023
Merged

Release #1492

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
6 changes: 6 additions & 0 deletions packages/g-gesture/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @antv/g-gesture

## 2.2.15

### Patch Changes

- 8c8a2729: Revert gesture.

## 2.2.14

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-gesture/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-gesture",
"version": "2.2.14",
"version": "2.2.15",
"description": "G Gesture",
"keywords": [
"antv",
Expand Down
27 changes: 2 additions & 25 deletions packages/g-gesture/src/gesture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {
FederatedPointerEvent,
PointLike as Point,
} from '@antv/g-lite';
import { ElementEvent } from '@antv/g-lite';
import EventEmitter from 'eventemitter3';

const clock =
Expand Down Expand Up @@ -85,32 +84,10 @@ class Gesture extends EventEmitter {

private _initEvent() {
const { el } = this;
if (el.isConnected) {
// @ts-ignore
el.ownerDocument?.defaultView.addEventListener('pointermove', this._move);
} else {
el.isMutationObserved = true;
el.on(ElementEvent.MOUNTED, (e) => {
el.ownerDocument?.defaultView.addEventListener(
'pointermove',
// @ts-ignore
this._move,
);
});
}

el.addEventListener('pointerdown', this._start);

if (el.isConnected) {
// @ts-ignore
el.ownerDocument?.defaultView.addEventListener('pointerup', this._end);
} else {
el.on(ElementEvent.MOUNTED, (e) => {
// @ts-ignore
el.ownerDocument?.defaultView.addEventListener('pointerup', this._end);
});
}

el.addEventListener('pointermove', this._move);
el.addEventListener('pointerup', this._end);
el.addEventListener('pointercancel', this._cancel);
el.addEventListener('pointerupoutside', this._end);
}
Expand Down
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);
}