Skip to content

Commit

Permalink
fix: types(NodeItem)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongfaqiu committed Sep 9, 2022
1 parent beebdd3 commit 95fb98b
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/GeoTimeScale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ export default class GeoTimeLine {
.attr("opacity", (d) =>
d.visible ? 1 : 0
)
.attr("display", (d) =>
d.visible ? 'block' : 'none'
)
.attr("transform", (d) => `translate(${d.targetX}, ${d.y})`)
.attr("dominant-baseline", "hanging")
.attr("text-anchor", (d) =>
Expand Down
191 changes: 190 additions & 1 deletion src/typing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HierarchyRectangularNode, ZoomTransform } from "d3";
import { ZoomTransform } from "d3";

/** geo time data intervals schema **/
export type IntervalItem = {
Expand Down Expand Up @@ -103,4 +103,193 @@ export type d3ZoomEvent = {
sourceEvent: WheelEvent | MouseEvent,
target: any;
transform: ZoomTransform;
}

// copy from d3
export interface HierarchyLink<Datum> {
/**
* The source of the link.
*/
source: HierarchyNode<Datum>;

/**
* The target of the link.
*/
target: HierarchyNode<Datum>;
}

export interface HierarchyNode<Datum> {
/**
* The associated data, as specified to the constructor.
*/
data: Datum;

/**
* Zero for the root node, and increasing by one for each descendant generation.
*/
readonly depth: number;

/**
* Zero for leaf nodes, and the greatest distance from any descendant leaf for internal nodes.
*/
readonly height: number;

/**
* The parent node, or null for the root node.
*/
parent: this | null;

/**
* An array of child nodes, if any; undefined for leaf nodes.
*/
children?: this[] | undefined;

/**
* Aggregated numeric value as calculated by `sum(value)` or `count()`, if previously invoked.
*/
readonly value?: number | undefined;

/**
* Optional node id string set by `StratifyOperator`, if hierarchical data was created from tabular data using stratify().
*/
readonly id?: string | undefined;

/**
* Returns the array of ancestors nodes, starting with this node, then followed by each parent up to the root.
*/
ancestors(): this[];

/**
* Returns the array of descendant nodes, starting with this node, then followed by each child in topological order.
*/
descendants(): this[];

/**
* Returns the array of leaf nodes in traversal order; leaves are nodes with no children.
*/
leaves(): this[];

/**
* Returns the first node in the hierarchy from this node for which the specified filter returns a truthy value. undefined if no such node is found.
* @param filter Filter.
*/
find(filter: (node: this) => boolean): this | undefined;

/**
* Returns the shortest path through the hierarchy from this node to the specified target node.
* The path starts at this node, ascends to the least common ancestor of this node and the target node, and then descends to the target node.
*
* @param target The target node.
*/
path(target: this): this[];

/**
* Returns an array of links for this node, where each link is an object that defines source and target properties.
* The source of each link is the parent node, and the target is a child node.
*/
links(): Array<HierarchyLink<Datum>>;

/**
* Evaluates the specified value function for this node and each descendant in post-order traversal, and returns this node.
* The `node.value` property of each node is set to the numeric value returned by the specified function plus the combined value of all descendants.
*
* @param value The value function is passed the node’s data, and must return a non-negative number.
*/
sum(value: (d: Datum) => number): this;

/**
* Computes the number of leaves under this node and assigns it to `node.value`, and similarly for every descendant of node.
* If this node is a leaf, its count is one. Returns this node.
*/
count(): this;

/**
* Sorts the children of this node, if any, and each of this node’s descendants’ children,
* in pre-order traversal using the specified compare function, and returns this node.
*
* @param compare The compare function is passed two nodes a and b to compare.
* If a should be before b, the function must return a value less than zero;
* if b should be before a, the function must return a value greater than zero;
* otherwise, the relative order of a and b are not specified. See `array.sort` for more.
*/
sort(compare: (a: this, b: this) => number): this;

/**
* Returns an iterator over the node’s descendants in breadth-first order.
*/
[Symbol.iterator](): Iterator<this>;

/**
* Invokes the specified function for node and each descendant in breadth-first order,
* such that a given node is only visited if all nodes of lesser depth have already been visited,
* as well as all preceding nodes of the same depth.
*
* @param func The specified function is passed the current descendant, the zero-based traversal index, and this node.
* @param that If that is specified, it is the this context of the callback.
*/
each<T = undefined>(func: (this: T, node: this, index: number, thisNode: this) => void, that?: T): this;

/**
* Invokes the specified function for node and each descendant in post-order traversal,
* such that a given node is only visited after all of its descendants have already been visited.
*
* @param func The specified function is passed the current descendant, the zero-based traversal index, and this node.
* @param that If that is specified, it is the this context of the callback.
*
*/
eachAfter<T = undefined>(func: (this: T, node: this, index: number, thisNode: this) => void, that?: T): this;

/**
* Invokes the specified function for node and each descendant in pre-order traversal,
* such that a given node is only visited after all of its ancestors have already been visited.
*
* @param func The specified function is passed the current descendant, the zero-based traversal index, and this node.
* @param that If that is specified, it is the this context of the callback.
*/
eachBefore<T = undefined>(func: (this: T, node: this, index: number, thisNode: this) => void, that?: T): this;

/**
* Return a deep copy of the subtree starting at this node. The returned deep copy shares the same data, however.
* The returned node is the root of a new tree; the returned node’s parent is always null and its depth is always zero.
*/
copy(): this;
}

export interface HierarchyRectangularLink<Datum> {
/**
* The source of the link.
*/
source: HierarchyRectangularNode<Datum>;

/**
* The target of the link.
*/
target: HierarchyRectangularNode<Datum>;
}
export interface HierarchyRectangularNode<Datum> extends HierarchyNode<Datum> {
/**
* The left edge of the rectangle.
*/
x0: number;

/**
* The top edge of the rectangle
*/
y0: number;

/**
* The right edge of the rectangle.
*/
x1: number;

/**
* The bottom edge of the rectangle.
*/
y1: number;

/**
* Returns an array of links for this node, where each link is an object that defines source and target properties.
* The source of each link is the parent node, and the target is a child node.
*/
links(): Array<HierarchyRectangularLink<Datum>>;
}

0 comments on commit 95fb98b

Please sign in to comment.