@neo4j-nvl/base 0.3.1-016e1c20

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.
Files changed (71) hide show
  1. package/LICENSE.txt +49 -0
  2. package/README.md +43 -0
  3. package/dist/base.mjs +2 -0
  4. package/dist/base.mjs.LICENSE.txt +10 -0
  5. package/dist/types/index.d.ts +379 -0
  6. package/dist/types/layouts/animatedlayout/AnimatedLayout.d.ts +25 -0
  7. package/dist/types/layouts/animatedlayout/animationUtils.d.ts +9 -0
  8. package/dist/types/layouts/d3forcelayout/circularLayout.d.ts +5 -0
  9. package/dist/types/layouts/d3forcelayout/constants.d.ts +18 -0
  10. package/dist/types/layouts/d3forcelayout/d3ForceLayout.d.ts +29 -0
  11. package/dist/types/layouts/d3forcelayout/types.d.ts +9 -0
  12. package/dist/types/layouts/forcedirectedlayout/ForceCytoLayout.d.ts +22 -0
  13. package/dist/types/layouts/forcedirectedlayout/cosebilkentlayout/CoseBilkentLayout.d.ts +32 -0
  14. package/dist/types/layouts/forcedirectedlayout/physlayout/PhysLayout.d.ts +167 -0
  15. package/dist/types/layouts/forcedirectedlayout/physlayout/glwrapper.d.ts +4 -0
  16. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-fragment.d.ts +2 -0
  17. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-repulsive-fragment.d.ts +2 -0
  18. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-update-fragment.d.ts +2 -0
  19. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/sim-vertex.d.ts +2 -0
  20. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/workaround-fragment.d.ts +2 -0
  21. package/dist/types/layouts/forcedirectedlayout/physlayout/solarmerger/SolarMerger.d.ts +43 -0
  22. package/dist/types/layouts/forcedirectedlayout/physlayout/solarmerger/solar-placer.d.ts +2 -0
  23. package/dist/types/layouts/freeLayout/FreeLayout.d.ts +26 -0
  24. package/dist/types/layouts/gridLayout/GridLayout.d.ts +16 -0
  25. package/dist/types/layouts/hierarchicallayout/HierarchicalLayout.d.ts +26 -0
  26. package/dist/types/layouts/hierarchicallayout/constants.d.ts +11 -0
  27. package/dist/types/modules/CallbackHelper.d.ts +38 -0
  28. package/dist/types/modules/ExternalCallbackHandler.d.ts +26 -0
  29. package/dist/types/modules/NvlController.d.ts +114 -0
  30. package/dist/types/modules/Shader.d.ts +18 -0
  31. package/dist/types/modules/ZoomTransitionHandler.d.ts +27 -0
  32. package/dist/types/modules/dataset.d.ts +37 -0
  33. package/dist/types/modules/logging.d.ts +8 -0
  34. package/dist/types/modules/performance.d.ts +93 -0
  35. package/dist/types/modules/state.d.ts +242 -0
  36. package/dist/types/renderers/canvasrenderer/Animation.d.ts +64 -0
  37. package/dist/types/renderers/canvasrenderer/AnimationHandler.d.ts +72 -0
  38. package/dist/types/renderers/canvasrenderer/CanvasRenderer.d.ts +92 -0
  39. package/dist/types/renderers/canvasrenderer/ImageCache.d.ts +11 -0
  40. package/dist/types/renderers/canvasrenderer/arrows/ArrowBundle.d.ts +79 -0
  41. package/dist/types/renderers/canvasrenderer/arrows/ArrowBundler.d.ts +33 -0
  42. package/dist/types/renderers/canvasrenderer/arrows/arrows.d.ts +52 -0
  43. package/dist/types/renderers/canvasrenderer/arrows/constants.d.ts +41 -0
  44. package/dist/types/renderers/canvasrenderer/nodes/nodes.d.ts +58 -0
  45. package/dist/types/renderers/canvasrenderer/types.d.ts +47 -0
  46. package/dist/types/renderers/canvasrenderer/util.d.ts +69 -0
  47. package/dist/types/renderers/canvasrenderer/vectorUtils.d.ts +21 -0
  48. package/dist/types/renderers/canvasrenderer/wordwrap.d.ts +42 -0
  49. package/dist/types/renderers/webglrenderer/Controller.d.ts +66 -0
  50. package/dist/types/renderers/webglrenderer/Renderer.d.ts +51 -0
  51. package/dist/types/renderers/webglrenderer/node-animation-fragment.d.ts +2 -0
  52. package/dist/types/renderers/webglrenderer/node-animation-vertex.d.ts +2 -0
  53. package/dist/types/renderers/webglrenderer/node-fragment-point.d.ts +2 -0
  54. package/dist/types/renderers/webglrenderer/node-vertex-point.d.ts +2 -0
  55. package/dist/types/renderers/webglrenderer/rel-fragment-line.d.ts +2 -0
  56. package/dist/types/renderers/webglrenderer/rel-vertex-line.d.ts +2 -0
  57. package/dist/types/renderers/webglrenderer/viewport-box-fragment.d.ts +2 -0
  58. package/dist/types/renderers/webglrenderer/viewport-box-vertex.d.ts +2 -0
  59. package/dist/types/types/graph-element.d.ts +117 -0
  60. package/dist/types/types/nvl-window-functions.d.ts +15 -0
  61. package/dist/types/types/utils.d.ts +1 -0
  62. package/dist/types/utils/canvasManagement.d.ts +15 -0
  63. package/dist/types/utils/colorMapperFunctions.d.ts +6 -0
  64. package/dist/types/utils/constants.d.ts +30 -0
  65. package/dist/types/utils/errors.d.ts +11 -0
  66. package/dist/types/utils/geometry.d.ts +122 -0
  67. package/dist/types/utils/graphObjectUtils.d.ts +9 -0
  68. package/dist/types/utils/hittest.d.ts +56 -0
  69. package/dist/types/utils/mouseUtils.d.ts +9 -0
  70. package/dist/types/utils/zoomFunctions.d.ts +20 -0
  71. package/package.json +65 -0
@@ -0,0 +1,52 @@
1
+ import type { BorderStyle } from '../../../modules/state';
2
+ import type { Node, Relationship } from '../../../types/graph-element';
3
+ import type { Point } from '../../../utils/geometry';
4
+ import ImageCache from '../ImageCache';
5
+ import type ArrowBundle from './ArrowBundle';
6
+ /**
7
+ * This function calculates the difference in radius between two nodes.
8
+ * @param {number} toArrowGap - The gap between the node and the arrow on the to side.
9
+ * @param {number} fromArrowGap - The gap between the node and the arrow on the from side.
10
+ * @returns {number} The difference in radius between the two nodes.
11
+ * @comment can be affected for example by the label crust and selected ring
12
+ * as well as a gap between the node and the arrow on it's side.
13
+ */
14
+ export declare const getRadiusDifference: (toArrowGap: number, fromArrowGap: number) => number;
15
+ /**
16
+ * This function calculates the coordinates of the via point
17
+ * between two nodes. The via point is used to bend the edge
18
+ * between the two nodes.
19
+ * @param {Node} fromNode - The node the edge starts from.
20
+ * @param {Node} toNode - The node the edge ends at.
21
+ * @param {number} fromArrowGap - The gap between the node and the arrow on the from side.
22
+ * @param {number} toArrowGap - The gap between the node and the arrow on the to side.
23
+ * @returns {Point} The coordinates of the via point.
24
+ */
25
+ export declare const getViaCoordinates: (fromNode: Node, toNode: Node, fromArrowGap: number, toArrowGap: number, rel: Relationship, bundle: ArrowBundle) => Point;
26
+ export declare const getPointsForStraight: (rel: Relationship, bundle: ArrowBundle, fromNode: Node, toNode: Node, showLabel: boolean, curved?: boolean) => Point[];
27
+ /**
28
+ * Draws a label for a relationship
29
+ * @param {CanvasRenderingContext2D} ctx - the canvas context
30
+ * @param {number} x - the x coordinate of the label
31
+ * @param {number} y - the y coordinate of the label
32
+ * @param {number} angle - the angle of the label
33
+ * @param {number} maxWidth - the maximum width of the label
34
+ * @param {Relationship} rel - the relationship
35
+ * @param {boolean} flip - whether to flip the label
36
+ */
37
+ export declare const drawLabel: (ctx: CanvasRenderingContext2D, point: Point, angle: number, maxWidth: number, rel: Relationship, bundle: ArrowBundle, flip?: boolean) => void;
38
+ export declare const renderWaypointArrow: (ctx: CanvasRenderingContext2D, rel: Relationship, from: Node, to: Node, bundle: ArrowBundle, imageCache: ImageCache, showLabel: boolean, drawCurves: boolean, selectedBorderStyle: BorderStyle) => void;
39
+ export declare const renderSelfArrow: (ctx: CanvasRenderingContext2D, rel: Relationship, node: Node, bundle: ArrowBundle, imageCache: ImageCache, showLabel: boolean, selectedBorderStyle: BorderStyle) => void;
40
+ export declare const renderArrow: (ctx: CanvasRenderingContext2D, rel: Relationship, fromNode: Node, toNode: Node, bundle: ArrowBundle, imageCache: ImageCache, showLabel: boolean, selectedBorderStyle: BorderStyle, drawCurves?: boolean) => void;
41
+ export declare const distanceToEdge: (pos: Point, rel: Relationship, fromNode: Node, toNode: Node, bundle: ArrowBundle, showLabel: boolean, drawCurves?: boolean) => number;
42
+ /**
43
+ * Returns the bounding box of the arrow.
44
+ * @param {Relationship} rel - The relationship to get the bounding box for.
45
+ * @param {ArrowBundle} bundle - The arrow bundle the relationship is part of.
46
+ * @param {Node} fromNode - The node the relationship is coming from.
47
+ * @param {Node} toNode - The node the relationship is going to.
48
+ * @param {boolean} showLabel - Whether or not a label is shown.
49
+ * @param {boolean} drawCurves - Whether or the relationship is drawn as a curve.
50
+ * @returns {DOMRect} The bounding box of the arrow.
51
+ */
52
+ export declare const getBoundingBox: (rel: Relationship, bundle: ArrowBundle, fromNode: Node, toNode: Node, showLabel?: boolean, drawCurves?: boolean) => DOMRect | null;
@@ -0,0 +1,41 @@
1
+ /** The gap between a node and a relationship. */
2
+ export declare const NodeGap = 4;
3
+ /** The increase of the gap between a node and relationship when the node is selected */
4
+ export declare const SelectGap = 4;
5
+ /** The width of arrow heads. */
6
+ export declare const HeadWidth = 7;
7
+ /** The height of arrow heads. */
8
+ export declare const HeadHeight = 9;
9
+ /** The chin height of arrows. */
10
+ export declare const HeadChinHeight = 2;
11
+ /** The default color of relationships. */
12
+ export declare const RelColor = "#848484";
13
+ /** The length of the curve of a curved relationship. */
14
+ export declare const TaperRelLength = 30;
15
+ /** The distance of the starting points of relationships in a bundle. */
16
+ export declare const BundleAngleSep: number;
17
+ /** The distance needed to draw an arrow head in a bundled relationship. */
18
+ export declare const BundleArrowDist = 8;
19
+ /** The distance needed to draw an arrow head in a detailed bundled relationship. */
20
+ export declare const BundleArrowDistDetailed = 17;
21
+ /** The angle of the starting - and ending points of a self-referring relationship. */
22
+ export declare const SelfRefAngle: number;
23
+ /** The width of a self-referring relationship. */
24
+ export declare const SelfRefWidth = 25;
25
+ /** The height of a self-referring relationship. */
26
+ export declare const SelfRefHeight = 35;
27
+ /** The maximum width of a self-referring relationship's label. */
28
+ export declare const SelfRefLabelMaxWidth = 40;
29
+ /** Width increase when a relationship is selected. */
30
+ export declare const SelectedWidthFactor = 1.5;
31
+ /** The style properties of a disabled relationship. */
32
+ export declare const Disabled: {
33
+ color: string;
34
+ fontColor: string;
35
+ };
36
+ /** The font styles for relationship captions. */
37
+ export declare const Font: {
38
+ size: number;
39
+ color: string;
40
+ face: string;
41
+ };
@@ -0,0 +1,58 @@
1
+ import type { BorderStyles } from '../../../modules/state';
2
+ import type { Node } from '../../../types/graph-element';
3
+ import type AnimationHandler from '../AnimationHandler';
4
+ type RingStyle = {
5
+ width: number;
6
+ color: string;
7
+ };
8
+ /**
9
+ * Returns an array of styles for the rings of a node.
10
+ * It takes the node as an argument, and an optional array of size animations.
11
+ * If the node is selected, it returns the selectedStyle.rings array.
12
+ * If the node is not selected, it returns an array containing only one object with
13
+ * a width of 0 and an empty color.
14
+ * @param node {Node} - The node to get the ring styles for.
15
+ * @param animationHandler {AnimationHandler} - The animation handler.
16
+ * @param nodeBorderStyles {BorderStyles} - The node border styles.
17
+ * @returns {{ width: number, color: string }[]} - An array of ring styles.
18
+ */
19
+ export declare const getRingStyles: (node: Node, animationHandler: AnimationHandler, nodeBorderStyles: any) => RingStyle[];
20
+ /**
21
+ * Returns the bounding box of a node with the given x, y, and size properties.
22
+ * If no size is given, the default size is used.
23
+ * @param {Node} Node - The node to get the bounding box for.
24
+ * @returns {object} The bounding box of the node.
25
+ */
26
+ export declare const getBoundingBox: ({ x, y, size }: Node) => DOMRect;
27
+ /**
28
+ * Returns the caption font size that should be used
29
+ * for the given info level and node diameter.
30
+ * @param infoLevel {number} - The info level.
31
+ * @param nodeRadius {number} - The radius of the node.
32
+ * @param captionSize {number} - The size of the caption.
33
+ * @returns {number} - The font size.
34
+ */
35
+ export declare const infoLevelToFontSize: (infoLevel: number, nodeRadius?: number, captionSize?: number, hasIcon?: boolean) => number;
36
+ /**
37
+ * Returns maximum length of lines
38
+ * @param lines {array} - The lines info
39
+ * @returns {number} - The font size.
40
+ */
41
+ export declare const findMaxLength: (lines: any[], ctx: CanvasRenderingContext2D, pixelRatio: number) => number;
42
+ /**
43
+ * Returns minimum length of lines
44
+ * @param lines {array} - The lines info
45
+ * @returns {number} - The font size.
46
+ */
47
+ export declare const findMinLength: (lines: any[], ctx: CanvasRenderingContext2D, pixelRatio: number) => any;
48
+ /**
49
+ * Draws a node with the given context, node, and image cache.
50
+ * @param ctx {any} - The context to draw the node on.
51
+ * @param node {Node} - The node to draw.
52
+ * @param imageCache {any} - The image cache to use.
53
+ * @param animationHandler {AnimationHandler} - The animation handler.
54
+ * @param nodeBorderStyles {BorderStyles} - The node border styles.
55
+ * @param zoomLevel {number} - The current zoom level.
56
+ */
57
+ export declare const drawNode: (ctx: CanvasRenderingContext2D, node: Node, imageCache: any, animationHandler: AnimationHandler, nodeBorderStyles: BorderStyles, zoomLevel?: number) => void;
58
+ export {};
@@ -0,0 +1,47 @@
1
+ import type { Node, Relationship } from '../../types/graph-element';
2
+ import type { Point } from '../../utils/geometry';
3
+ export type TextSegment = {
4
+ hasEllipsisChar?: boolean;
5
+ hasHyphenChar?: boolean;
6
+ text: string;
7
+ overflowed?: boolean;
8
+ };
9
+ /**
10
+ * The caption text and its text style.
11
+ * @property styles - The font styles as comma separated values
12
+ * @example 'bold,italic'
13
+ * @property value - The text for the caption.
14
+ * @property key - The caption identifier key.
15
+ */
16
+ export type StyledCaption = {
17
+ styles?: string[];
18
+ value?: string;
19
+ key?: string;
20
+ };
21
+ export type StyledCaptionWithChars = StyledCaption & {
22
+ chars?: string[][];
23
+ };
24
+ export type CacheItem = {
25
+ image?: CacheInfo;
26
+ inverted?: CacheInfo;
27
+ };
28
+ export type CacheInfo = {
29
+ canvas: HTMLCanvasElement;
30
+ image: HTMLImageElement;
31
+ drawn: boolean;
32
+ };
33
+ export type Cache = Record<string, CacheItem>;
34
+ export interface RelationshipToRender extends Relationship {
35
+ fromNode: Node;
36
+ toNode: Node;
37
+ showLabel: boolean;
38
+ }
39
+ export interface WaypointPath {
40
+ points: Point[];
41
+ from: Point;
42
+ to: Point;
43
+ }
44
+ export interface ArrowBundleGap {
45
+ size: number;
46
+ start: number;
47
+ }
@@ -0,0 +1,69 @@
1
+ import type { Point } from '../../utils/geometry';
2
+ import type { TextSegment } from './types';
3
+ export declare const fontThresholds: number[][];
4
+ /**
5
+ * This function takes color in hex format or rgb() or rgba() format and overrides the opacity. Returns rgba() string.
6
+ * @param {string} color
7
+ * @param {number} opacity
8
+ * @returns {string} rgba() string with the given opacity
9
+ */
10
+ export declare const overrideOpacity: (color: string, opacity: number) => string;
11
+ /**
12
+ * The parameters for drawing an arrowhead.
13
+ */
14
+ type ArrowHeadParameters = {
15
+ headPosition: Point;
16
+ headAngle: number;
17
+ headHeight: number;
18
+ headChinHeight: number;
19
+ headWidth: number;
20
+ };
21
+ /**
22
+ * Creates an arrowhead shape using a polygon.
23
+ * @param {CanvasRenderingContext2D} ctx - The canvas context to draw on.
24
+ * @param {number} headLineWidth - The width of the arrowhead's outline.
25
+ * @param {string} color - The color of the arrowhead.
26
+ * @param {ArrowHeadParameters} arrowHeadParameters - The parameters for the arrowhead.
27
+ * @param {boolean} fill - Whether or not to fill the triangle.
28
+ * @param {boolean} stroke - Whether or not to stroke the triangle.
29
+ */
30
+ export declare const drawArrowHead: (ctx: CanvasRenderingContext2D, headLineWidth: number, color: string, arrowHeadParameters: ArrowHeadParameters, fill?: boolean, stroke?: boolean) => void;
31
+ /**
32
+ * Draws borders around a node with a given array of border styles
33
+ * @param {CanvasRenderingContext2D} ctx - The canvas context
34
+ * @param {number} x - The x coordinate of the node
35
+ * @param {number} y - The y coordinate of the node
36
+ * @param {number} innerRadius - The inner radius of the node without any border
37
+ * @param {Array} borderStyles - An array of border styles
38
+ * @internal
39
+ */
40
+ export declare const drawCircleBand: (ctx: CanvasRenderingContext2D, x: number, y: number, innerRadius: number, borderStyles: {
41
+ width: number;
42
+ color: string;
43
+ }[]) => void;
44
+ export declare const drawCircle: (ctx: CanvasRenderingContext2D, x: number, y: number, r: number) => void;
45
+ /**
46
+ * Fill a circle band with a gradient from a certain color to transparent
47
+ * @param {CanvasRenderingContext2D} ctx - The canvas context
48
+ * @param {number} x - The x coordinate of the node
49
+ * @param {number} y - The y coordinate of the node
50
+ * @param {string} color - The color of the gradient
51
+ * @param {number} radius - The inner radius of the node without any border
52
+ * @param {number} blur - The blur radius of the gradient
53
+ * @param {number} maxOpacity - The maximum opacity of the gradient
54
+ */
55
+ export declare const drawGradientCircleBand: (ctx: CanvasRenderingContext2D, x: number, y: number, color: string, radius: number, blur: number, maxOpacity?: number) => void;
56
+ /**
57
+ * Draw a circle shape with a solid color
58
+ */
59
+ export declare const drawSolidCircle: (ctx: CanvasRenderingContext2D, x: number, y: number, color: string, size: number) => void;
60
+ export declare function getIndividualInfoLevels(r: number, zoomLevel: number): {
61
+ nodeInfoLevel: number;
62
+ fontInfoLevel: number;
63
+ iconInfoLevel: number;
64
+ };
65
+ /**
66
+ * Prints the caption for a node
67
+ */
68
+ export declare const drawNodeCaption: (ctx: CanvasRenderingContext2D, lines: TextSegment[], stylesPerChar: string[][], initialYPos: number, fontSize: number, fontFace: string, lineDistance: number, x: number, y: number) => void;
69
+ export {};
@@ -0,0 +1,21 @@
1
+ import type { Point } from '../../utils/geometry';
2
+ export declare const add: (v1: Point, v2: Point) => {
3
+ x: number;
4
+ y: number;
5
+ };
6
+ export declare const sub: (v1: Point, v2: Point) => {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ export declare const scale: (v: Point, s: number) => {
11
+ x: number;
12
+ y: number;
13
+ };
14
+ export declare const dot: (v1: Point, v2: Point) => number;
15
+ export declare const getModule: (v1: Point) => number;
16
+ export declare const distance: (v1: Point, v2: Point) => number;
17
+ export declare const angle: (v1: Point, v2: Point) => number;
18
+ export declare const coordFromPolar: (polarAngle: number, polarModule: number) => {
19
+ x: number;
20
+ y: number;
21
+ };
@@ -0,0 +1,42 @@
1
+ import type { StyledCaption, TextSegment } from './types';
2
+ export declare const hyphenChar = "\u2010";
3
+ export declare const ellipsisChar = "\u2026";
4
+ /**
5
+ * This is the main function that tries to fit a text on one or more lines
6
+ *
7
+ * @param {string} text = The full string to place
8
+ * @param {function} measureWidth - a function that returns the width of a string as pixels on the canvas
9
+ * @param {function} getAvailbleWidth - A function providing the pixel width for a line index
10
+ * @param {number} numberOfLines - How many lines is availble for this placement
11
+ * @param {boolean} allowedToGiveUp - If cannot fit on last avilble line - should we give up or place as much as we can
12
+ *
13
+ * @return array of text lines
14
+ */
15
+ export declare const tryWithNumberOfLines: (text: string, measureWidth: (text: string) => number, getAvailableWidth: (a: number, b: number) => number, numberOfLines: number, allowedToGiveUp?: boolean) => TextSegment[];
16
+ /**
17
+ * This functions tries to fit the text in a given number of lines and only linebreak on whitespace
18
+ *
19
+ * @param {string} text = The full string to place
20
+ * @param {function} measureWidth - a function that returns the width of a string as pixels on the canvas
21
+ * @param {function} getAvailbleWidth - A function providing the pixel width for a line index
22
+ * @param {number} numberOfLines - How many lines is availble for this placement
23
+ *
24
+ * @return array of text lines
25
+ */
26
+ export declare const tryBreakingOnSpaces: (text: string, measureWidth: (text: string) => number, getAvailableWidth: (a: number, b: number) => number, numberOfLines: number) => TextSegment[];
27
+ /**
28
+ * @param {object} ctx = Canvas.2dContext
29
+ * @param {object} text - The text to display
30
+ *
31
+ * @return array of text lines
32
+ */
33
+ export declare const getLines: (ctx: CanvasRenderingContext2D, text: string, fontFace: string, fontSize: string | number, maxWidth: number, hasIcon: boolean, fontInfoLevel: number, align: string) => TextSegment[];
34
+ /**
35
+ * Returns the styles by char for a group of property values
36
+ * @param {array} captions = array of captions
37
+ * @return array of list of styles by char
38
+ */
39
+ export declare const getStylesByChar: (captions?: StyledCaption[]) => {
40
+ stylesPerChar: string[][];
41
+ fullCaption: string;
42
+ };
@@ -0,0 +1,66 @@
1
+ import type { Node, Relationship } from '../../index';
2
+ import type { DataSet } from '../../modules/dataset';
3
+ import type { NvlState } from '../../modules/state';
4
+ import type Renderer from './Renderer';
5
+ export interface ControllerInterface {
6
+ mainSceneRenderer: Renderer;
7
+ minimapRenderer: Renderer;
8
+ needsRun: boolean;
9
+ minimapMouseDown: boolean;
10
+ stateDisposers: NvlState['autorun'][];
11
+ state: NvlState;
12
+ needsToRun: () => boolean;
13
+ renderMainScene: (positionArray: Node[]) => void;
14
+ renderMinimap: (positionArray: Node[]) => void;
15
+ checkForUpdates: (nodes: DataSet<Node>, rels: DataSet<Relationship>) => void;
16
+ onResize: () => void;
17
+ updateMainViewport: (zoom: number, panX: number, panY: number) => void;
18
+ updateMinimapViewport: (zoom: number, panX: number, panY: number) => void;
19
+ handleMinimapDrag: (e: MouseEvent) => void;
20
+ handleMinimapWheel: (evt: MouseEvent) => void;
21
+ setupMinimapInteractions: () => void;
22
+ destroy: () => void;
23
+ }
24
+ export default class Controller implements ControllerInterface {
25
+ mainSceneRenderer: Renderer;
26
+ minimapRenderer: Renderer;
27
+ needsRun: boolean;
28
+ minimapMouseDown: boolean;
29
+ stateDisposers: NvlState['autorun'][];
30
+ state: NvlState;
31
+ constructor(options: {
32
+ mainSceneRenderer?: Renderer;
33
+ minimapRenderer?: Renderer;
34
+ state: NvlState;
35
+ });
36
+ needsToRun(): boolean;
37
+ renderMainScene(positionArray: any): void;
38
+ renderMinimap(positionArray: Node[]): void;
39
+ checkForUpdates(nodes: DataSet<Node>, rels: DataSet<Relationship>): void;
40
+ onResize(): void;
41
+ updateMainViewport(zoom: number, panX: number, panY: number): void;
42
+ updateMinimapViewport(zoom: number, panX: number, panY: number): void;
43
+ handleMinimapDrag(e: MouseEvent): void;
44
+ handleMinimapWheel(evt: WheelEvent): void;
45
+ setupMinimapInteractions(): void;
46
+ destroy(): void;
47
+ }
48
+ export declare class DummyController implements ControllerInterface {
49
+ mainSceneRenderer: Renderer;
50
+ minimapRenderer: Renderer;
51
+ needsRun: boolean;
52
+ minimapMouseDown: boolean;
53
+ stateDisposers: NvlState['autorun'][];
54
+ state: NvlState;
55
+ renderMainScene(positionArray: Node[]): void;
56
+ renderMinimap(positionArray: Node[]): void;
57
+ checkForUpdates(nodes: DataSet<Node>, rels: DataSet<Relationship>): void;
58
+ onResize(): void;
59
+ updateMainViewport(zoom: number, panX: number, panY: number): void;
60
+ updateMinimapViewport(zoom: number, panX: number, panY: number): void;
61
+ handleMinimapDrag(e: MouseEvent): void;
62
+ handleMinimapWheel(e: MouseEvent): void;
63
+ setupMinimapInteractions(): void;
64
+ destroy(): void;
65
+ needsToRun(): boolean;
66
+ }
@@ -0,0 +1,51 @@
1
+ import { mat4 } from 'gl-matrix';
2
+ import type { DataSet } from '../../modules/dataset';
3
+ import type { NvlState } from '../../modules/state';
4
+ import type { Node, Relationship } from '../../types/graph-element';
5
+ export default class Renderer {
6
+ private readonly nodeShader;
7
+ private readonly nodeAnimShader;
8
+ private readonly relShader;
9
+ private relDataBuffer;
10
+ private readonly viewportBoxShader;
11
+ private readonly defaultRelColor;
12
+ private readonly defaultNodeColor;
13
+ private readonly disableRelColor;
14
+ private readonly disableNodeColor;
15
+ private readonly gl;
16
+ activeNodes: Record<string, boolean>;
17
+ readonly canvas: HTMLCanvasElement;
18
+ projection: mat4;
19
+ private idToIndex;
20
+ private posBuffer;
21
+ private numRels;
22
+ private numNodes;
23
+ private nodeDataByte;
24
+ private relIdToIndex;
25
+ private relData;
26
+ private containerWidth;
27
+ private containerHeight;
28
+ private nodeDataInt;
29
+ private viewportBoxBuffer;
30
+ private relBuffer;
31
+ private nodeBuffer;
32
+ private posTexture;
33
+ constructor(gl: WebGLRenderingContext, nodes: DataSet<Node>, rels: DataSet<Relationship>, state: NvlState);
34
+ private setShaderUniforms;
35
+ setData(data: {
36
+ nodes: Node[];
37
+ rels: Relationship[];
38
+ }): void;
39
+ render(positionArray: Node[], nodes: any, rels: any): void;
40
+ renderViewbox(): void;
41
+ updateNodes(updates: Node[]): void;
42
+ updateRelationships(relItems: Relationship[]): void;
43
+ private createPositionTexture;
44
+ updateViewportBox(zoom: number, panX: number, panY: number, viewportWidth: number, viewportHeight: number): void;
45
+ updateViewport(zoom: number, panX: number, panY: number): void;
46
+ private setupViewportRendering;
47
+ private setupNodeRendering;
48
+ private setupRelationshipRendering;
49
+ private renderAnimations;
50
+ destroy(): void;
51
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: "uniform mediump float u_zoom;\nuniform lowp float u_animPos;\nuniform mediump float u_glAdjust;\n\nvarying lowp vec4 color;\nvarying lowp float varNodeSize;\nmediump float circleSize = 0.50;\n\nvoid main(void) {\n\n lowp float dist = distance(gl_PointCoord, vec2(0.5));\n\n if (dist > 0.51) {\n discard;\n }\n else {\n lowp float alpha = 1.0 - smoothstep(circleSize - (1.0 / (varNodeSize * 2.0 * u_zoom * u_glAdjust)), circleSize, dist);\n lowp float pulseAlpha = 0.9 - 0.9 * u_animPos;\n gl_FragColor = vec4(color.xyz, 1.0) * alpha * pulseAlpha;\n }\n}\n";
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: "uniform mat4 u_projection;\nuniform sampler2D u_positions;\nuniform lowp float u_animPos;\nuniform mediump float u_zoom;\nuniform mediump float u_glAdjust;\n\nattribute float a_size;\nattribute lowp vec2 a_index;\nattribute lowp vec4 a_color;\nattribute lowp float a_active;\n\nvarying lowp float varNodeSize;\nvarying lowp vec4 color;\n\nvoid main(void) {\n vec4 data = texture2D(u_positions, a_index);\n\n gl_Position = u_projection * vec4(data.xy, 0.0, 1.0);\n\n float nodeSize = a_size * u_zoom * u_glAdjust;\n nodeSize = nodeSize * (0.4 / 0.5); // Remove extra space added for shadow and selection ring\n\n gl_PointSize = a_active > 0.5\n ? nodeSize + 0.88 * nodeSize * u_animPos\n : 0.0;\n\n color = a_color;\n varNodeSize = a_size;\n}";
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: "uniform mediump float u_zoom;\nuniform mediump float u_glAdjust;\n\nvarying lowp vec4 color;\nvarying lowp float drawDefaultBorder;\nvarying lowp vec3 nodeBorderColor;\nvarying lowp vec3 selectedBorderColor;\nvarying lowp float selected;\nvarying lowp float hovered;\nvarying lowp float varNodeSize;\n\nmediump float circleSize = 0.40;\nmediump float ringSize = 0.43;\nmediump float ringSize2 = 0.47;\nmediump float shadowSize = 0.51;\nlowp vec3 shadowColor = vec3(0.73);\nlowp vec3 lineColor = vec3(1.0);\n\nlowp float getShadowAlpha(lowp float size, lowp float dist) {\n return (1.0 - smoothstep(size, shadowSize, dist)) * 0.25;\n}\n\nlowp float getCircleAlpha(lowp float ringSize, lowp float nodeSize, lowp float dist) {\n return color.w - smoothstep(ringSize - nodeSize, ringSize, dist);\n}\n\nvoid main() {\n lowp float dist = distance(gl_PointCoord, vec2(0.5));\n\n if (dist > 0.51) {\n discard;\n }\n else {\n lowp float nodeSize = 1.0 / varNodeSize;\n lowp float nodeAlpha = getCircleAlpha(circleSize, nodeSize, dist);\n lowp float ringAlpha = getCircleAlpha(ringSize, nodeSize, dist);\n lowp vec3 finalColor = color.xyz;\n lowp float finalAlpha = nodeAlpha;\n\n if (selected > 0.0) {\n lowp float shadowAlpha = getShadowAlpha(ringSize2, dist);\n lowp float ringAlpha2 = getCircleAlpha(ringSize2, nodeSize, dist);\n\n finalColor = mix(lineColor, finalColor, nodeAlpha);\n finalColor = mix(selectedBorderColor, finalColor, ringAlpha);\n finalColor = mix(shadowColor, finalColor, ringAlpha2);\n finalAlpha = max(shadowAlpha, max(nodeAlpha, max(ringAlpha, ringAlpha2)));\n } else if (hovered > 0.0) {\n if (drawDefaultBorder > 0.0) {\n lowp float shadowAlpha = getShadowAlpha(ringSize, dist);\n \n finalColor = mix(nodeBorderColor, finalColor, nodeAlpha);\n finalColor = mix(shadowColor, finalColor, ringAlpha);\n finalAlpha = max(shadowAlpha, max(nodeAlpha, ringAlpha));\n } else {\n lowp float shadowAlpha = getShadowAlpha(circleSize, dist);\n\n finalColor = mix(shadowColor, finalColor, nodeAlpha);\n finalAlpha = max(shadowAlpha, nodeAlpha);\n }\n } else {\n if (drawDefaultBorder > 0.0) {\n finalColor = mix(nodeBorderColor, finalColor, nodeAlpha);\n finalAlpha = ringAlpha;\n }\n }\n gl_FragColor = vec4(finalColor, 1.0) * finalAlpha;\n }\n}\n";
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: "uniform mat4 u_projection;\nuniform sampler2D u_positions;\nuniform mediump float u_zoom;\nuniform mediump float u_glAdjust;\nuniform lowp vec3 u_nodeBorderColor;\nuniform lowp vec3 u_selectedBorderColor;\nuniform lowp float u_drawDefaultBorder;\n\nattribute float a_size;\nattribute lowp vec2 a_index;\nattribute lowp vec4 a_color;\nattribute lowp float a_selected;\nattribute lowp float a_hovered;\n\nvarying lowp float window;\nvarying lowp vec4 color;\nvarying lowp float selected;\nvarying lowp float hovered;\nvarying lowp float varNodeSize;\nvarying lowp vec3 nodeBorderColor;\nvarying lowp vec3 selectedBorderColor;\nvarying lowp float drawDefaultBorder;\n\nlowp float MinNodeSize = 5.0;\n\nvoid main(void) {\n vec4 data = texture2D(u_positions, a_index);\n gl_Position = u_projection * vec4(data.xy, 0.0, 1.0);\n\n lowp float nodeSize = a_size * u_zoom * u_glAdjust;\n if (nodeSize < MinNodeSize) {\n gl_PointSize = MinNodeSize;\n varNodeSize = MinNodeSize;\n } else {\n gl_PointSize = nodeSize;\n varNodeSize = nodeSize;\n }\n\n color = a_color;\n selected = a_selected;\n hovered = a_hovered;\n nodeBorderColor = u_nodeBorderColor;\n selectedBorderColor = u_selectedBorderColor;\n drawDefaultBorder = u_drawDefaultBorder;\n}";
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: "varying lowp vec4 color;\n\nvoid main(void) {\n gl_FragColor = vec4(color.xyz, 1.0) * color.w;\n}\n";
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: "uniform mat4 u_projection;\nuniform sampler2D u_positions;\nuniform mediump float u_glAdjust;\n\nattribute vec2 a_from;\nattribute vec2 a_to;\nattribute lowp vec4 a_color;\nattribute lowp float a_triside;\nattribute float a_width;\n\nvarying lowp vec4 color;\n\nvoid main(void) {\n vec4 from = texture2D(u_positions, a_from);\n vec4 to = texture2D(u_positions, a_to);\n vec2 direction = normalize(to.xy - from.xy);\n direction = vec2(-direction.y, direction.x);\n\n float width = a_width * u_glAdjust * 0.5;\n\n if (a_triside == 0.0) {\n from.y += (width / 2.0) * direction.y;\n from.x += (width / 2.0) * direction.x;\n } else {\n from.y -= (width / 2.0) * direction.y;\n from.x -= (width / 2.0) * direction.x;\n }\n\n color = a_color;\n gl_Position = u_projection * vec4(from.xy, 0.0, 1.0);\n}\n";
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: "void main(void) {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n}\n";
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: "attribute vec2 coordinates;\nuniform mat4 u_projection;\n\nvoid main(void) {\n gl_Position = u_projection * vec4(coordinates, 0.0, 1.0);\n}\n";
2
+ export default _default;
@@ -0,0 +1,117 @@
1
+ import type { StyledCaption } from '../renderers/canvasrenderer/types';
2
+ /**
3
+ * The base type for graph elements.
4
+ * @private
5
+ * @internal
6
+ */
7
+ interface GraphElement {
8
+ /**
9
+ * The id of the current node or relationship.
10
+ * @note ids need to be unique across all nodes and relationships.
11
+ * @note ids need to be strings and cannot be empty.
12
+ */
13
+ readonly id: string;
14
+ color?: string;
15
+ /** Whether or not the current node or relationship is selected.*/
16
+ selected?: boolean;
17
+ /** The text to display inside on node or relationship.
18
+ * @deprecated Use {@link captions} instead.
19
+ */
20
+ caption?: string;
21
+ /** Whether or not the current node or relationship is disabled.*/
22
+ disabled?: boolean;
23
+ /** Whether or not the current node or relationship is hovered.*/
24
+ hovered?: boolean;
25
+ /** The caption text size.*/
26
+ captionSize?: number;
27
+ /**
28
+ * The caption align.
29
+ * @note Has no affect on self-referring relationships.
30
+ */
31
+ captionAlign?: 'top' | 'bottom' | 'center';
32
+ /** The caption text and font style.*/
33
+ captions?: StyledCaption[];
34
+ /**
35
+ * An icon to be displayed anywhere on top of the graph element.
36
+ * @note Icons are expected to be square.
37
+ */
38
+ overlayIcon?: {
39
+ url: string;
40
+ /**
41
+ * The position of the icon relative to the node or relationship.
42
+ * @note The position is a percentage of the node or relationship size.
43
+ * `[1, 1]` is the bottom right corner of the node or relationship.
44
+ * `[-1, -1]` is the top left corner of the node or relationship.
45
+ * @defaultValue `[0, 0]`, the center of the node or relationship.
46
+ */
47
+ position?: number[];
48
+ /**
49
+ * The size of the icon relative to the node size or relationship caption size.
50
+ * @note The size is a percentage of the node size or relationship caption size.
51
+ * @defaultValue `1`, the same size as the node size or relationship caption size.
52
+ */
53
+ size?: number;
54
+ };
55
+ }
56
+ export declare const isValidNode: (node: unknown) => node is Node;
57
+ /**
58
+ * A node inside the graph visualization.
59
+ */
60
+ interface Node extends GraphElement {
61
+ /** The size of the node.*/
62
+ size?: number;
63
+ /** Whether or not the current node is pinned.*/
64
+ pinned?: boolean;
65
+ /** The x-coordinate for the position of the node.*/
66
+ x?: number;
67
+ /** The y-coordinate for the position of the node.*/
68
+ y?: number;
69
+ /** Whether or not the current node is activated.*/
70
+ activated?: boolean;
71
+ /**
72
+ * The url to an icon to display inside the node.
73
+ * @note Icons are expected to be black. If the node's background color is dark,
74
+ * the icon will be inverted to white.
75
+ * @note Icons are expected to be square.
76
+ */
77
+ icon?: string;
78
+ /**
79
+ * The DOM element to display on top of a node.
80
+ * @experimental
81
+ */
82
+ html?: HTMLElement;
83
+ }
84
+ /**
85
+ * @internal
86
+ */
87
+ type PartialNode = Partial<Node> & {
88
+ id: string;
89
+ };
90
+ export declare const isValidRelationship: (relationship: unknown) => relationship is Relationship;
91
+ /**
92
+ * A relationship inside the graph visualization.
93
+ */
94
+ interface Relationship extends GraphElement {
95
+ /** Node id where the relationship starts from.*/
96
+ from: string;
97
+ /** Node id where the relationship points to.*/
98
+ to: string;
99
+ /** The relationship type.*/
100
+ type?: string;
101
+ /** The width of the relationship.*/
102
+ width?: number;
103
+ /**
104
+ * The DOM element to display on top of a relationship caption.
105
+ * @experimental
106
+ * @note The {@link captionSize} and {@link captionAlign} properties
107
+ * will affect the position and height of the html container element.
108
+ */
109
+ captionHtml?: HTMLElement;
110
+ }
111
+ /**
112
+ * @internal
113
+ */
114
+ type PartialRelationship = Partial<Relationship> & {
115
+ id: string;
116
+ };
117
+ export type { Node, Relationship, PartialNode, PartialRelationship };
@@ -0,0 +1,15 @@
1
+ import type { Node, Relationship } from './graph-element';
2
+ export interface NvlWindow {
3
+ __Nvl_dumpNodes: (instanceId?: string) => Node[];
4
+ __Nvl_dumpRelationships: (instanceId?: string) => Relationship[];
5
+ __Nvl_getNodesOnScreen: (instanceId?: string) => {
6
+ nodes: Node[];
7
+ rels: Relationship[];
8
+ };
9
+ __Nvl_registerDoneCallback: (cb: () => void, instanceId: string) => void;
10
+ __Nvl_getZoomLevel: (instanceId?: string) => number;
11
+ }
12
+ declare global {
13
+ interface Window extends NvlWindow {
14
+ }
15
+ }
@@ -0,0 +1 @@
1
+ export declare const typedObjectEntries: <T>(obj: T) => [keyof T, T[keyof T]][];
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Fixes the canvas size to match the parent element's size.
3
+ * @param canvas The canvas to fix the size of.
4
+ *
5
+ * @note Make sure canvas pixel buffer is 1 to 1 vs screen pixels
6
+ */
7
+ export declare const fitCanvasSizeToParent: (canvas: HTMLCanvasElement) => void;
8
+ export declare const addWebGLContextLostListener: (canvas: HTMLCanvasElement, contextLostCallback?: (e: WebGLContextEvent) => void) => void;
9
+ export declare const createCanvasForScreenshot: (fullWidth: number, fullHeight: number) => HTMLCanvasElement;
10
+ export declare const createCanvasForRenderer: (parent?: HTMLElement, onContextLostCallback?: (e: WebGLContextEvent) => void) => HTMLCanvasElement;
11
+ export declare const removeCanvas: (canvas: HTMLCanvasElement) => void;
12
+ export declare const getCanvas2DContext: (canvas: HTMLCanvasElement) => CanvasRenderingContext2D;
13
+ export declare const getWebGLContext: (canvas: HTMLCanvasElement) => WebGLRenderingContext | WebGL2RenderingContext;
14
+ export declare const removeWebGLContext: (webGLCtx: WebGLRenderingContext) => void;
15
+ export declare const checkWebGLAvailability: (canvas?: HTMLCanvasElement) => boolean;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Determines whether a black or white font color is more readable for a given background color
3
+ * @param {string} color The background color
4
+ * @returns {string} The font color that should be used @defaultValue '#fff'
5
+ */
6
+ export declare const textColorForBackground: (color: string) => string;