@krainovsd/graph 0.8.4 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.cjs +569 -162
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/lib/get-controls-info.js +212 -65
- package/lib/esm/lib/get-controls-info.js.map +1 -1
- package/lib/esm/module/GraphCanvas/GraphCanvas.js +260 -76
- package/lib/esm/module/GraphCanvas/GraphCanvas.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/settings.js +41 -20
- package/lib/esm/module/GraphCanvas/constants/settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js +55 -0
- package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js.map +1 -0
- package/lib/esm/module/GraphCanvas/lib/utils/node-by-pointer-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/pointer-getter.js +8 -2
- package/lib/esm/module/GraphCanvas/lib/utils/pointer-getter.js.map +1 -1
- package/lib/index.d.ts +67 -26
- package/package.json +1 -1
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
function pointerGetter(mouseEvent, areaRect, areaTransform) {
|
|
2
|
-
const
|
|
3
|
-
|
|
2
|
+
const clientX = "clientX" in mouseEvent
|
|
3
|
+
? mouseEvent.clientX
|
|
4
|
+
: (mouseEvent.touches[0]?.clientX ?? mouseEvent.changedTouches[0]?.clientX);
|
|
5
|
+
const clientY = "clientX" in mouseEvent
|
|
6
|
+
? mouseEvent.clientY
|
|
7
|
+
: (mouseEvent.touches[0]?.clientY ?? mouseEvent.changedTouches[0]?.clientY);
|
|
8
|
+
const px = (clientX - areaRect.left - areaTransform.x) / areaTransform.k;
|
|
9
|
+
const py = (clientY - areaRect.top - areaTransform.y) / areaTransform.k;
|
|
4
10
|
return [px, py];
|
|
5
11
|
}
|
|
6
12
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pointer-getter.js","sources":["../../../../../../src/module/GraphCanvas/lib/utils/pointer-getter.ts"],"sourcesContent":["import type { ZoomTransform } from \"d3-zoom\";\n\nexport function pointerGetter(\n mouseEvent: MouseEvent,\n areaRect: DOMRect,\n areaTransform: ZoomTransform,\n) {\n const
|
|
1
|
+
{"version":3,"file":"pointer-getter.js","sources":["../../../../../../src/module/GraphCanvas/lib/utils/pointer-getter.ts"],"sourcesContent":["import type { ZoomTransform } from \"d3-zoom\";\n\nexport function pointerGetter(\n mouseEvent: MouseEvent | TouchEvent,\n areaRect: DOMRect,\n areaTransform: ZoomTransform,\n) {\n const clientX =\n \"clientX\" in mouseEvent\n ? mouseEvent.clientX\n : (mouseEvent.touches[0]?.clientX ?? mouseEvent.changedTouches[0]?.clientX);\n const clientY =\n \"clientX\" in mouseEvent\n ? mouseEvent.clientY\n : (mouseEvent.touches[0]?.clientY ?? mouseEvent.changedTouches[0]?.clientY);\n\n const px = (clientX - areaRect.left - areaTransform.x) / areaTransform.k;\n const py = (clientY - areaRect.top - areaTransform.y) / areaTransform.k;\n\n return [px, py];\n}\n"],"names":[],"mappings":"SAEgB,aAAa,CAC3B,UAAmC,EACnC,QAAiB,EACjB,aAA4B,EAAA;AAE5B,IAAA,MAAM,OAAO,GACX,SAAS,IAAI;UACT,UAAU,CAAC;WACV,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;AAC/E,IAAA,MAAM,OAAO,GACX,SAAS,IAAI;UACT,UAAU,CAAC;WACV,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;AAE/E,IAAA,MAAM,EAAE,GAAG,CAAC,OAAO,GAAG,QAAQ,CAAC,IAAI,GAAG,aAAa,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC;AACxE,IAAA,MAAM,EAAE,GAAG,CAAC,OAAO,GAAG,QAAQ,CAAC,GAAG,GAAG,aAAa,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC;AAEvE,IAAA,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC;AACjB;;;;"}
|
package/lib/index.d.ts
CHANGED
|
@@ -22,11 +22,11 @@ interface LinkInterface<NodeData extends Record<string, unknown>, LinkData exten
|
|
|
22
22
|
type ZoomEventInterface = D3ZoomEvent<HTMLCanvasElement, unknown>;
|
|
23
23
|
type DragEventInterface<NodeData extends Record<string, unknown>> = D3DragEvent<HTMLElement, unknown, NodeInterface<NodeData>>;
|
|
24
24
|
type ListenersInterface<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> = {
|
|
25
|
-
onContextMenu?: (event: MouseEvent, node
|
|
26
|
-
onClick?: (event: MouseEvent, node
|
|
27
|
-
onDoubleClick?: (event: MouseEvent, node
|
|
28
|
-
onWheelClick?: (event: MouseEvent, node
|
|
29
|
-
onMove?: (event: MouseEvent, node
|
|
25
|
+
onContextMenu?: (event: MouseEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
|
|
26
|
+
onClick?: (event: MouseEvent | TouchEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
|
|
27
|
+
onDoubleClick?: (event: MouseEvent | TouchEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
|
|
28
|
+
onWheelClick?: (event: MouseEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
|
|
29
|
+
onMove?: (event: MouseEvent | TouchEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
|
|
30
30
|
onZoom?: (event: ZoomEventInterface) => void;
|
|
31
31
|
onDragSubject?: (event: DragEventInterface<NodeData>, state: GraphState<NodeData, LinkData>) => NodeInterface<NodeData> | undefined;
|
|
32
32
|
onDraw?: (state: GraphState<NodeData, LinkData>, toggleHighlightStatus: (status: boolean) => void, clearHighlightState: () => void) => void;
|
|
@@ -38,19 +38,33 @@ type ListenersInterface<NodeData extends Record<string, unknown>, LinkData exten
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
type GraphSettingsInterface<NodeData extends Record<string, unknown>> = {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
highlightByNodeOnlyRoot?: boolean;
|
|
42
|
+
highlightByNodeNodeFadingMin?: number;
|
|
43
|
+
highlightByNodeLinkFadingMin?: number;
|
|
44
|
+
highlightByNodeArrowFadingMin?: number;
|
|
45
|
+
highlightByNodeNodeColorFadingMin?: number;
|
|
46
|
+
highlightByNodeTextFadingMin?: number;
|
|
47
|
+
highlightByNodeNodeSizingAdditional?: number;
|
|
48
|
+
highlightByNodeTextSizingAdditional?: number;
|
|
49
|
+
highlightByNodeTextShiftXAdditional?: number;
|
|
50
|
+
highlightByNodeTextShiftYAdditional?: number;
|
|
51
|
+
highlightByNodeTextWeightAdditional?: number;
|
|
52
|
+
highlightByNodeTextWidthAdditional?: number;
|
|
53
|
+
highlightByLinkOnlyRoot?: boolean;
|
|
54
|
+
highlightByLinkNodeFadingMin?: number;
|
|
55
|
+
highlightByLinkLinkFadingMin?: number;
|
|
56
|
+
highlightByLinkArrowFadingMin?: number;
|
|
57
|
+
highlightByLinkNodeColorFadingMin?: number;
|
|
58
|
+
highlightByLinkTextFadingMin?: number;
|
|
59
|
+
highlightByLinkNodeSizingAdditional?: number;
|
|
60
|
+
highlightByLinkTextSizingAdditional?: number;
|
|
61
|
+
highlightByLinkTextShiftXAdditional?: number;
|
|
62
|
+
highlightByLinkTextShiftYAdditional?: number;
|
|
63
|
+
highlightByLinkTextWeightAdditional?: number;
|
|
64
|
+
highlightByLinkTextWidthAdditional?: number;
|
|
65
|
+
highlightByHoverNode?: boolean;
|
|
66
|
+
highlightByHoverLink?: boolean;
|
|
67
|
+
hoverLinkThreshold?: number;
|
|
54
68
|
highlightDownStep?: number;
|
|
55
69
|
highlightUpStep?: number;
|
|
56
70
|
stickAfterDrag?: boolean;
|
|
@@ -107,11 +121,16 @@ type NodeOptionsInterface<NodeData extends Record<string, unknown>, LinkData ext
|
|
|
107
121
|
textDraw?: ((node: NodeInterface<NodeData>, options: Required<NodeOptionsInterface<NodeData, LinkData>>, state: GraphState<NodeData, LinkData>) => void) | null;
|
|
108
122
|
nodeExtraDraw?: ((node: NodeInterface<NodeData>, options: Required<NodeOptionsInterface<NodeData, LinkData>>, state: GraphState<NodeData, LinkData>) => void) | null;
|
|
109
123
|
textExtraDraw?: ((node: NodeInterface<NodeData>, options: Required<NodeOptionsInterface<NodeData, LinkData>>, state: GraphState<NodeData, LinkData>) => void) | null;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
124
|
+
highlightByNodeNodeFading?: boolean;
|
|
125
|
+
highlightByNodeNodeSizing?: boolean;
|
|
126
|
+
highlightByNodeTextFading?: boolean;
|
|
127
|
+
highlightByNodeTextSizing?: boolean;
|
|
128
|
+
highlightByNodeNodeColor?: boolean;
|
|
129
|
+
highlightByLinkNodeFading?: boolean;
|
|
130
|
+
highlightByLinkNodeSizing?: boolean;
|
|
131
|
+
highlightByLinkTextFading?: boolean;
|
|
132
|
+
highlightByLinkTextSizing?: boolean;
|
|
133
|
+
highlightByLinkNodeColor?: boolean;
|
|
115
134
|
borderColor?: string;
|
|
116
135
|
borderWidth?: number;
|
|
117
136
|
radius?: number;
|
|
@@ -143,13 +162,15 @@ type LinkOptionsInterface<NodeData extends Record<string, unknown>, LinkData ext
|
|
|
143
162
|
alpha?: number;
|
|
144
163
|
color?: string;
|
|
145
164
|
width?: number;
|
|
146
|
-
|
|
165
|
+
highlightByNodeLinkFading?: boolean;
|
|
166
|
+
highlightByNodeArrowFading?: boolean;
|
|
167
|
+
highlightByLinkLinkFading?: boolean;
|
|
168
|
+
highlightByLinkArrowFading?: boolean;
|
|
147
169
|
pretty?: boolean;
|
|
148
170
|
arrow?: boolean;
|
|
149
171
|
arrowAlpha?: number;
|
|
150
172
|
arrowColor?: string;
|
|
151
173
|
arrowSize?: number;
|
|
152
|
-
arrowHighlightFading?: boolean;
|
|
153
174
|
arrowReverseAppear?: boolean;
|
|
154
175
|
particleAlpha?: number;
|
|
155
176
|
particleColor?: string;
|
|
@@ -180,6 +201,7 @@ type GraphState<NodeData extends Record<string, unknown>, LinkData extends Recor
|
|
|
180
201
|
simulationWorking: boolean;
|
|
181
202
|
isDragging: boolean;
|
|
182
203
|
highlightedNode: NodeInterface<NodeData> | null;
|
|
204
|
+
highlightedLink: LinkInterface<NodeData, LinkData> | null;
|
|
183
205
|
highlightedNeighbors: Set<string | number> | null;
|
|
184
206
|
highlightProgress: number;
|
|
185
207
|
highlightWorking: boolean;
|
|
@@ -235,6 +257,7 @@ declare class GraphCanvas<NodeData extends Record<string, unknown>, LinkData ext
|
|
|
235
257
|
private nodeOptionsCache;
|
|
236
258
|
private isDragging;
|
|
237
259
|
private highlightedNode;
|
|
260
|
+
private highlightedLink;
|
|
238
261
|
private highlightedNeighbors;
|
|
239
262
|
private highlightProgress;
|
|
240
263
|
private highlightWorking;
|
|
@@ -287,6 +310,15 @@ declare function nodeRadiusGetter({ radiusFlexible, radiusInitial, linkCount, ra
|
|
|
287
310
|
declare function linkIterationExtractor<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>, Result extends string | number | boolean | Record<string, unknown> | unknown[]>(link: LinkInterface<NodeData, LinkData>, i: number, links: LinkInterface<NodeData, LinkData>[], state: GraphState<NodeData, LinkData>, option: LinkIterationPropsInterface<NodeData, LinkData, Result> | Result, optionConstantGetter: undefined): Result;
|
|
288
311
|
declare function linkIterationExtractor<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>, Result extends string | number | boolean | Record<string, unknown> | unknown[]>(link: LinkInterface<NodeData, LinkData>, i: number, links: LinkInterface<NodeData, LinkData>[], state: GraphState<NodeData, LinkData>, option: LinkIterationPropsInterface<NodeData, LinkData, Result> | Result, optionConstantGetter: LinkIterationPropsInterface<NodeData, LinkData, Required<Result>> | Required<Result>): Required<Result>;
|
|
289
312
|
|
|
313
|
+
type NodeByPointerGetterOptions<NodeData extends Record<string, unknown>> = {
|
|
314
|
+
mouseEvent: MouseEvent | TouchEvent;
|
|
315
|
+
areaRect: DOMRect | undefined;
|
|
316
|
+
areaTransform: ZoomTransform;
|
|
317
|
+
nodes: NodeInterface<NodeData>[];
|
|
318
|
+
graphSettings: Required<GraphSettingsInterface<NodeData>>;
|
|
319
|
+
};
|
|
320
|
+
declare function nodeByPointerGetter<NodeData extends Record<string, unknown>>({ areaRect, areaTransform, mouseEvent, nodes, graphSettings, }: NodeByPointerGetterOptions<NodeData>): NodeInterface<NodeData> | undefined;
|
|
321
|
+
|
|
290
322
|
declare function nodeIterationExtractor<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>, Result extends string | number | boolean | Record<string, unknown> | unknown[] | undefined | null>(node: NodeInterface<NodeData>, i: number, nodes: NodeInterface<NodeData>[], state: GraphState<NodeData, LinkData>, option: NodeIterationPropsInterface<NodeData, LinkData, Result> | Result, optionConstantGetter: undefined): Result;
|
|
291
323
|
declare function nodeIterationExtractor<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>, Result extends string | number | boolean | Record<string, unknown> | unknown[] | undefined | null>(node: NodeInterface<NodeData>, i: number, nodes: NodeInterface<NodeData>[], state: GraphState<NodeData, LinkData>, option: NodeIterationPropsInterface<NodeData, LinkData, Result> | Result, optionConstantGetter: NodeIterationPropsInterface<NodeData, LinkData, Result> | Result): Required<Result>;
|
|
292
324
|
|
|
@@ -327,6 +359,15 @@ type GetParticlePositionOptions = {
|
|
|
327
359
|
};
|
|
328
360
|
declare function getParticlePosition(opts: GetParticlePositionOptions): void;
|
|
329
361
|
|
|
362
|
+
type LinkByPointerGetterOptions<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> = {
|
|
363
|
+
mouseEvent: MouseEvent | TouchEvent;
|
|
364
|
+
areaRect: DOMRect | undefined;
|
|
365
|
+
areaTransform: ZoomTransform;
|
|
366
|
+
links: LinkInterface<NodeData, LinkData>[];
|
|
367
|
+
graphSettings: Required<GraphSettingsInterface<NodeData>>;
|
|
368
|
+
};
|
|
369
|
+
declare function linkByPointerGetter<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>>({ areaRect, areaTransform, mouseEvent, links, graphSettings, }: LinkByPointerGetterOptions<NodeData, LinkData>): LinkInterface<NodeData, LinkData> | undefined;
|
|
370
|
+
|
|
330
371
|
declare function colorToRgb(color: string): string | null;
|
|
331
372
|
|
|
332
373
|
declare function extractRgb(color: string | null): {
|
|
@@ -367,4 +408,4 @@ declare function getGraphControls<NodeData extends Record<string, unknown>>(keys
|
|
|
367
408
|
declare function getNodeControls<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>>(keys?: (keyof NodeOptionsInterface<NodeData, LinkData>)[]): GraphSettingsInputInterface<keyof NodeOptionsInterface<NodeData, LinkData>>[];
|
|
368
409
|
declare function getLinkControls<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>>(keys?: (keyof LinkOptionsInterface<NodeData, LinkData>)[]): GraphSettingsInputInterface<keyof LinkOptionsInterface<NodeData, LinkData>>[];
|
|
369
410
|
|
|
370
|
-
export { type CachedNodeTextInterface, type DragEventInterface, type ForceSettingsInterface, GraphCanvas, type GraphCanvasInterface, type GraphCanvasSimulation, type GraphParticle, type GraphSettingsInterface, type GraphState, type LinkInterface, type LinkIterationPropsInterface, type LinkOptionsInterface, type LinkSettingsInterface, type ListenersInterface, type NodeInterface, type NodeIterationPropsInterface, type NodeOptionsInterface, type NodeSettingsInterface, type RGB, type TextStyleEnum, type ZoomEventInterface, animationByProgress, calculateLinkPositionByRadius, colorToRgb, drawText, extractRgb, fadeRgb, getForceControls, getGraphControls, getLinkControls, getNodeControls, getParticlePosition, linkIterationExtractor, linkOptionsGetter, nodeIterationExtractor, nodeOptionsGetter, nodeRadiusGetter, rgbAnimationByProgress };
|
|
411
|
+
export { type CachedNodeTextInterface, type DragEventInterface, type ForceSettingsInterface, GraphCanvas, type GraphCanvasInterface, type GraphCanvasSimulation, type GraphParticle, type GraphSettingsInterface, type GraphState, type LinkInterface, type LinkIterationPropsInterface, type LinkOptionsInterface, type LinkSettingsInterface, type ListenersInterface, type NodeInterface, type NodeIterationPropsInterface, type NodeOptionsInterface, type NodeSettingsInterface, type RGB, type TextStyleEnum, type ZoomEventInterface, animationByProgress, calculateLinkPositionByRadius, colorToRgb, drawText, extractRgb, fadeRgb, getForceControls, getGraphControls, getLinkControls, getNodeControls, getParticlePosition, linkByPointerGetter, linkIterationExtractor, linkOptionsGetter, nodeByPointerGetter, nodeIterationExtractor, nodeOptionsGetter, nodeRadiusGetter, rgbAnimationByProgress };
|