@visuallyjs/browser-ui 1.1.4 → 1.2.1

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 (32) hide show
  1. package/css/visuallyjs.css +10 -0
  2. package/js/visuallyjs.browser-ui.cjs.js +53 -53
  3. package/js/visuallyjs.browser-ui.esm.js +53 -53
  4. package/package.json +1 -1
  5. package/types/browser-ui/auto-pan-handler.d.ts +10 -1
  6. package/types/browser-ui/browser-visuallyjs-instance.d.ts +6 -0
  7. package/types/browser-ui/components/inspector/definitions.d.ts +1 -0
  8. package/types/browser-ui/components/inspector/inspector.d.ts +2 -2
  9. package/types/browser-ui/dialogs/binder.d.ts +2 -1
  10. package/types/browser-ui/dialogs/constants.d.ts +1 -0
  11. package/types/browser-ui/pan-zoom.d.ts +14 -15
  12. package/types/browser-ui/paper-renderer/definitions.d.ts +9 -0
  13. package/types/browser-ui/paper-renderer/paper.d.ts +15 -0
  14. package/types/browser-ui/plugins/background/generated-grid-background.d.ts +1 -1
  15. package/types/browser-ui/surface-renderer/index.d.ts +1 -0
  16. package/types/browser-ui/surface-renderer/popups/definitions.d.ts +14 -0
  17. package/types/browser-ui/surface-renderer/popups/index.d.ts +3 -0
  18. package/types/browser-ui/surface-renderer/popups/popup-handler.d.ts +28 -0
  19. package/types/browser-ui/surface-renderer/popups/util.d.ts +4 -0
  20. package/types/browser-ui/surface-renderer/surface.d.ts +22 -9
  21. package/types/charts/sankey/sankey.d.ts +1 -1
  22. package/types/core/geom.d.ts +10 -4
  23. package/types/core/layout/circular/circular-layout.d.ts +6 -1
  24. package/types/core/params.d.ts +16 -16
  25. package/types/core/search/visuallyjs-search.d.ts +4 -6
  26. package/types/core/selection.d.ts +6 -2
  27. package/types/core/toolkit.d.ts +15 -7
  28. package/types/core/util.d.ts +5 -0
  29. package/types/ui/core/constants.d.ts +7 -0
  30. package/types/ui/core/core.d.ts +4 -0
  31. package/types/ui/core/definitions.d.ts +9 -0
  32. package/types/version.d.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visuallyjs/browser-ui",
3
- "version": "1.1.4",
3
+ "version": "1.2.1",
4
4
  "license": "Commercial",
5
5
  "main": "js/visuallyjs.browser-ui.cjs.js",
6
6
  "module": "js/visuallyjs.browser-ui.esm.js",
@@ -1,11 +1,12 @@
1
1
  import { PointXY } from "../core";
2
- import { SupportsElementDragging } from "../ui";
2
+ import { AutoPanBoundsStrategy, SupportsElementDragging } from "../ui";
3
3
  import { BrowserElement } from "./util";
4
4
  export interface AutoPanOptions {
5
5
  autoPanDelta?: number;
6
6
  autoPanRepeat?: number;
7
7
  onPan: (deltas: PointXY) => void;
8
8
  shouldHandle: () => boolean;
9
+ boundsStrategy?: AutoPanBoundsStrategy;
9
10
  }
10
11
  /**
11
12
  * Manages auto pan for a component that supports dragging of elements (not just vertex elements, any elements, such as those used to manage edge dragging or lasso etc).
@@ -19,6 +20,7 @@ export declare class AutoPanHandler {
19
20
  private _lastPanDirection;
20
21
  private _isPanRepeatActive;
21
22
  private _rootBounds;
23
+ private _boundsStrategy;
22
24
  constructor(draggableInstance: SupportsElementDragging<BrowserElement>, options: AutoPanOptions);
23
25
  /**
24
26
  * Called by ElementDragHandler2 to continuously update the auto-pan logic during a drag.
@@ -27,6 +29,13 @@ export declare class AutoPanHandler {
27
29
  updateDragElementPosition(boundingClientRect: DOMRect): void;
28
30
  $updateRootBounds(): void;
29
31
  private _isElementIntersectingRoot;
32
+ private _isElementContainedRoot;
33
+ /**
34
+ * Determines whether or not the given rect is conside to be inside the root bounds, depending on the current bounds strategy.
35
+ * @param boundingClientRect
36
+ * @private
37
+ */
38
+ private _isElementInsideRootBounds;
30
39
  private _updatePanDirectionAndStartRepeat;
31
40
  private _stopPanRepeatInternal;
32
41
  reset(): void;
@@ -40,6 +40,7 @@ export declare abstract class BrowserUI<EVT = any> extends UICore<BrowserElement
40
40
  private readonly _managedElementsSelector;
41
41
  private readonly _hoverEvents;
42
42
  private readonly _eventManager;
43
+ private _elementEventFilterSelectors;
43
44
  private _canDropHandler;
44
45
  private _transferrableVertexAttributes;
45
46
  /**
@@ -59,6 +60,11 @@ export declare abstract class BrowserUI<EVT = any> extends UICore<BrowserElement
59
60
  * @internal
60
61
  */
61
62
  $canDrop(candidate: Node | Group, target?: Node | Group, onCanvas?: boolean): boolean;
63
+ /**
64
+ * Adds a CSS3 selector filter which will exclude the given element (and descendants) from reporting element events. Used internally by popups, but exposed in the API as it may be useful.
65
+ * @param selector A valid CSS3 selector.
66
+ */
67
+ addElementEventFilter(selector: string): void;
62
68
  $vertexRendered<N extends Vertex>(v: N, el: BrowserElement, def: VertexMapping<any, BrowserElement>, eventInfo?: {
63
69
  position: PointXY;
64
70
  }): void;
@@ -84,6 +84,7 @@ export type FieldInfo = {
84
84
  commonValue: any;
85
85
  editedValue?: any;
86
86
  attribute: string;
87
+ portId?: string;
87
88
  };
88
89
  /**
89
90
  * Options for the VanillaInspector, an instance of Inspector that uses VisuallyJs's default templating mechanism to render elements.
@@ -77,7 +77,7 @@ export declare class Inspector extends VjsContext {
77
77
  protected $_recomputeCommonData(): void;
78
78
  private __filterEmptyStrings;
79
79
  /**
80
- * Write the changes to the toolkit.
80
+ * Write the changes to the model.
81
81
  * @param updates
82
82
  * @internal
83
83
  */
@@ -107,7 +107,7 @@ export declare class Inspector extends VjsContext {
107
107
  * @param value
108
108
  *
109
109
  */
110
- setValue(key: string, value: any, repaintAfterwards?: boolean): void;
110
+ setValue(key: string, value: any, portId: string, repaintAfterwards?: boolean): void;
111
111
  /**
112
112
  * @internal
113
113
  * @param b
@@ -22,6 +22,7 @@ export declare function attemptCoerce(value: string, datatype: SupportedCoercion
22
22
  * @internal
23
23
  */
24
24
  export declare function extractValueFromElement(el: HTMLElement, unresolvedElementGetter?: (el: Element) => any): any;
25
+ export declare function $makeFieldKey(att: string, portSeparator: string, portId: string | null): string;
25
26
  /**
26
27
  * Apply the given object to the given DOM element. This method will find all child elements of `el` that have a `vjs-att`
27
28
  * attribute set, and then attempt to set the value of any found DOM element with a value extracted from `dataset`.
@@ -30,7 +31,7 @@ export declare function extractValueFromElement(el: HTMLElement, unresolvedEleme
30
31
  * @param autoCommitHandler
31
32
  * @internal
32
33
  */
33
- export declare function apply(dataset: Record<string, any>, el: any, autoCommitHandler?: (e: Element) => any, unresolvedElementSetter?: (e: Element, value: any) => any): void;
34
+ export declare function apply(dataset: Record<string, any>, el: any, portSeparator: string, autoCommitHandler?: (e: Element) => any): void;
34
35
  /**
35
36
  * @internal
36
37
  */
@@ -6,6 +6,7 @@ export declare const DialogConstants: {
6
6
  VJS_COMMIT: string;
7
7
  MULTIPLE: string;
8
8
  VJS: string;
9
+ VJS_PORT: string;
9
10
  DATATYPE: string;
10
11
  TITLE: string;
11
12
  FOCUS: string;
@@ -470,7 +470,7 @@ export declare class PanZoom {
470
470
  */
471
471
  setTransformOrigin(x: number, y: number): void;
472
472
  /**
473
- * Maps the given page location to a value relative to the viewport origin, allowing for zoom and pan of the canvas. This takes into account the offset of the viewport in the page so that what you get back is the mapped position relative to the target element's [left,top] corner. If you wish, you can supply true for 'doNotAdjustForOffset', to suppress that behavior.
473
+ * Maps the given page location to a value relative to the viewport origin, allowing for zoom and pan of the canvas. This takes into account the offset of the viewport in the page so that what you get back is the mapped position relative to the target element's [left,top] corner.
474
474
  * @param left X location
475
475
  * @param top Y location
476
476
  * @param roundValues If true, return integers.
@@ -479,13 +479,19 @@ export declare class PanZoom {
479
479
  fromPageLocation(left: number, top: number, roundValues?: boolean): PointXY;
480
480
  fromWindowLocation(left: number, top: number, roundValues?: boolean): PointXY;
481
481
  /**
482
- * Maps the given location on the canvas to a point relative to the page origin, allowing for zoom and
483
- * pan of the canvas. This takes into account the offset of the viewport in the page so that what
484
- * you get back is the mapped position computed relative to the target element's [left,top] corner.
482
+ * Maps the given location on the canvas to a point relative to the page origin, allowing for zoom and pan of the canvas. This takes into account the offset of the viewport in the page so that what you get back is the mapped position computed relative to the target element's [left,top] corner.
485
483
  * @param left
486
484
  * @param top
487
485
  */
488
486
  toPageLocation(left: number, top: number): PointXY;
487
+ /**
488
+ * Maps the given canvas location to a point, in page coordinates, relative to the panzoom container's origin. A return value of [0,0] from this method indicates the top left corner of the surface's container as seen by the user; negative values for x and/or y mean that the point is not in the visible viewport. Similarly, values for x greater the container width, or y greater than the container height, indicate that the point is not in the visible viewport.
489
+ *
490
+ * This method is useful when you want to position an element over the canvas at some specific canvas location. For instance, the SurfacePopup components use this to position themselves relative to the vertex they are currently referencing.
491
+ * @param left
492
+ * @param top
493
+ */
494
+ toViewportLocation(left: number, top: number): PointXY;
489
495
  /**
490
496
  * Maps the page location of the given event to a value relative to the viewport origin, allowing for zoom and pan of the canvas. This takes into account the offset of the viewport in the page so that what you get back is the mapped position relative to the target element's [left,top] corner. If you wish, you can supply true for 'doNotAdjustForOffset', to suppress that behavior.
491
497
  * @param event Browser event
@@ -498,10 +504,7 @@ export declare class PanZoom {
498
504
  */
499
505
  setEnabled(state: boolean): void;
500
506
  /**
501
- * Returns the apparent origin of the canvas inside the viewport - the coordinates, in real pixel
502
- * values, of where the origin of the canvas appears to be. This apparent origin is not necessarily the
503
- * same as the origin values of the canvas, because the transform origin and zoom values change
504
- * things. This function can be used in conjunction with the content bounds by widgets such as the miniview, to calculate what is actually visible in the viewport at some point in time.
507
+ * Returns the apparent origin of the canvas inside the viewport - the coordinates, in real pixel values, of where the origin of the canvas appears to be. This apparent origin is not necessarily the same as the origin values of the canvas, because the transform origin and zoom values change things. This function can be used in conjunction with the content bounds by widgets such as the miniview, to calculate what is actually visible in the viewport at some point in time.
505
508
  * @returns Position of the canvas, relative to the viewport's 0,0.
506
509
  */
507
510
  getApparentCanvasLocation(): PointXY;
@@ -517,16 +520,13 @@ export declare class PanZoom {
517
520
  */
518
521
  getVisibleContentArea(): RectangleXY;
519
522
  /**
520
- * Appends an element to the viewport so that it floats above the content that is being zoomed and panned.
521
- * The element will have `position:absolute` set on it. You can float any element you like, but note that the
522
- * responsibility for setting an appropriate z index is yours.
523
+ * Appends an element to the viewport so that it floats above the content that is being zoomed and panned. The element will have `position:absolute` set on it. You can float any element you like, but note that the responsibility for setting an appropriate z index is yours.
523
524
  * @param el - Element to float.
524
525
  * @param pos - Position to float the element at.
525
526
  */
526
527
  floatElement(el: Element, pos: PointXY): void;
527
528
  /**
528
- * Appends an element to the viewport such that it is zoomed with everything else, but constrains pan
529
- * in one or both axes so that the element remains fixed with respect to the viewport origin.
529
+ * Appends an element to the viewport such that it is zoomed with everything else, but constrains pan in one or both axes so that the element remains fixed with respect to the viewport origin.
530
530
  * @param el The DOM element to append.
531
531
  * @param pos Location of the element's origin.
532
532
  * @param constraints Flags to indicate optional constraint to each axis.
@@ -564,8 +564,7 @@ export declare class PanZoom {
564
564
  */
565
565
  destroy(): void;
566
566
  /**
567
- * returns whether or not the given element is owned by the current background, if there is one. with some library
568
- * integrations the background can be temporarily null during the processing of an event.
567
+ * returns whether or not the given element is owned by the current background, if there is one. with some library integrations the background can be temporarily null during the processing of an event.
569
568
  * @internal
570
569
  * @param el
571
570
  */
@@ -7,6 +7,14 @@ import { BrowserUIDefaults, BrowserUIOptions } from "../definitions";
7
7
  * @category Paper
8
8
  */
9
9
  export declare const CLASS_PAPER = "vjs-paper";
10
+ /**
11
+ * Css class added to a Paper component's container element when scaling is switched off.
12
+ * @cssClass
13
+ * @context paper
14
+ * @group Components
15
+ * @category Paper
16
+ */
17
+ export declare const CLASS_PAPER_NO_SCALE = "vjs-paper-no-scale";
10
18
  /**
11
19
  * Css class added to the DOM element used to render a Paper object.
12
20
  * @group Components
@@ -75,6 +83,7 @@ export interface PaperOptions extends BrowserUIOptions<PaperDefaults> {
75
83
  * Strategy to use to place content within whitespace in the vertical axis.
76
84
  */
77
85
  verticalAlign?: PaperAlignment;
86
+ scale?: boolean;
78
87
  }
79
88
  /**
80
89
  * Defaults for a Paper renderer
@@ -16,6 +16,7 @@ export declare class Paper extends BrowserUI {
16
16
  $margin: number;
17
17
  $horizontalAlign: PaperAlignment;
18
18
  $verticalAlign: PaperAlignment;
19
+ $scale: boolean;
19
20
  /**
20
21
  * @internal
21
22
  * @param model
@@ -41,6 +42,20 @@ export declare class Paper extends BrowserUI {
41
42
  fromWindowLocation(left: number, top: number, roundValues?: boolean): PointXY;
42
43
  mapEventLocation(event: MouseEvent): PointXY;
43
44
  getViewportBoundsInfo(): ViewportBounds;
45
+ /**
46
+ * When not scaling, this method is used by the background to determine what size it should be.
47
+ * @internal
48
+ */
49
+ $getFixedViewportBoundsInfo(): {
50
+ x: number;
51
+ y: number;
52
+ width: number;
53
+ height: number;
54
+ vw: number;
55
+ vh: number;
56
+ zoom: number;
57
+ minimumFill: number;
58
+ };
44
59
  getApparentCanvasLocation(): PointXY;
45
60
  addBackground(background: Background): void;
46
61
  removeBackground(background: Background): void;
@@ -168,7 +168,7 @@ export declare const CLASS_BACKGROUND_GRID_DOT_MINOR = "vjs-background-grid-dott
168
168
  * lines or dots - control this via the `gridType` option.
169
169
  *
170
170
  * The size of the grid can be mandated in the options for the background, or
171
- * it can be extracted from the surface.
171
+ * it can be extracted from the UI.
172
172
  *
173
173
  * You can hide/show the background grid via the `hide()`, `show()`, `toggle()` or `setVisible(boolean)`
174
174
  * methods.
@@ -16,6 +16,7 @@ export * from './surface-events';
16
16
  export * from './surface-render-options';
17
17
  export * from './diagrams';
18
18
  export * from './css-classes';
19
+ export * from "./popups";
19
20
  /**
20
21
  * Register a new decorator for use with the {@link Surface} component.
21
22
  * @param name Name to use when registering the decorator.
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The attribute uyed to instruct a PopupHandler where to place a popup with respect to the vertex it is attached to.
3
+ */
4
+ export declare const ATTRIBUTE_POPUP_POSITION = "data-vjs-popup-position";
5
+ /**
6
+ * Possible values for the popup position attribute.
7
+ */
8
+ export type PopupPosition = "top" | "bottom" | "left" | "right" | "center";
9
+ /**
10
+ * CSS class written on surface popups
11
+ * @cssClass
12
+ * @context Popups
13
+ */
14
+ export declare const CLASS_SURFACE_POPUP = "vjs-surface-popup";
@@ -0,0 +1,3 @@
1
+ export * from "./definitions";
2
+ export * from "./popup-handler";
3
+ export * from "./util";
@@ -0,0 +1,28 @@
1
+ import { PopupPosition } from "./definitions";
2
+ import { Vertex } from "../../../core";
3
+ import { BrowserElement } from "../../util";
4
+ import { ViewportElement } from "../../../ui";
5
+ import { Surface } from "../surface";
6
+ /**
7
+ * A handler for popups to appear in relation to vertices on the canvas. This class manages positioning of the popup and provision of the current vertex, but not the display of the popup itself, which is delegated to the library integrations
8
+ */
9
+ export declare class PopupHandler {
10
+ _current: ViewportElement<any> | null;
11
+ _anchor: PopupPosition;
12
+ _defaultAnchor: PopupPosition;
13
+ setCurrent: (v: Vertex | null) => any;
14
+ container: BrowserElement;
15
+ surface: Surface;
16
+ _cleanup: () => void;
17
+ private _doSetCurrent;
18
+ constructor(selector: string, container: BrowserElement, surface: Surface, setCurrent: (v: Vertex | null) => any, anchor?: PopupPosition);
19
+ $destroy(): void;
20
+ /**
21
+ * Sets the current object to null, which hides the popup
22
+ */
23
+ $hide(): void;
24
+ /**
25
+ * @internal
26
+ */
27
+ $positionPopup(): void;
28
+ }
@@ -0,0 +1,4 @@
1
+ import { PointXY, Size } from "../../../core";
2
+ import { ViewportElement } from "../../../ui";
3
+ import { Surface } from "../surface";
4
+ export declare function computeOrigin(anchor: string, referenceElement: ViewportElement<any>, popupSize: Size, surface: Surface): PointXY;
@@ -412,6 +412,11 @@ export declare class Surface extends BrowserUI<SurfaceEvents> implements Support
412
412
  * Gets the current bounds information.
413
413
  */
414
414
  getViewportBoundsInfo(): ViewportBounds;
415
+ /**
416
+ * Surface does not have fixed viewport bounds.
417
+ * @internal
418
+ */
419
+ $getFixedViewportBoundsInfo(): ViewportBounds | null;
415
420
  getApparentCanvasLocation(): PointXY;
416
421
  /**
417
422
  * Adds a background. Theoretically you can add multiple backgrounds but the end result of that is indeterminate.
@@ -508,21 +513,22 @@ export declare class Surface extends BrowserUI<SurfaceEvents> implements Support
508
513
  *
509
514
  */
510
515
  setPanAndZoom(x: number, y: number, zoom: number, animate?: boolean): void;
516
+ private __findBoundsForElements;
511
517
  /**
512
- * Center on the current object and zoom in on it.
513
- * @param element - The element to center. Can be a DOM element, vertex id, or a Node/Group
518
+ * Center on the current object/objects and zoom in on it/them.
519
+ * @param element - The element(s) to center. Can be a DOM element, vertex id, or a Node/Group, or an array of these.
514
520
  * @param fillRatio How much of the viewport to fill with the object we zoom in on. This will be limited by the current zoom range. Defaults to 0.6.
515
521
  * @param doNotAnimate - by default, this operation will be animated.
516
522
  * @canvasPosition
517
523
  *
518
524
  */
519
- centerOnAndZoom(element: string | Vertex | Element, fillRatio?: number, doNotAnimate?: boolean): void;
525
+ centerOnAndZoom(element: string | Vertex | Element | Array<string | Vertex | Element>, fillRatio?: number, doNotAnimate?: boolean): void;
520
526
  /**
521
- * Takes a node/group as argument and positions the surface canvas such that the given node is at the center in both axes.
522
- * @param element - The element to center. Can be a DOM element, vertex id, or a Node/Group.
527
+ * Takes a single node/group, or an array of nodes/groups, and positions the surface canvas such that the given vertex/vertices is/are at the center in both axes. It does NOT change the zoom.
528
+ * @param element - The element(s) to center. Can be a DOM element, vertex id, or a Node/Group, or an array of these.
523
529
  * @canvasPosition
524
530
  */
525
- centerOn(element: string | Vertex | Element): void;
531
+ centerOn(element: string | Vertex | Element | Array<string | Vertex | Element>, doNotAnimate?: boolean): void;
526
532
  /**
527
533
  * Takes a node/group as argument and positions the surface canvas such that the given node is at the center in the horizontal axis.
528
534
  * @param element - The element to center. Can be a DOM element, vertex id, or a Node/Group
@@ -574,13 +580,20 @@ export declare class Surface extends BrowserUI<SurfaceEvents> implements Support
574
580
  */
575
581
  fromWindowLocation(left: number, top: number, roundValues?: boolean): PointXY;
576
582
  /**
577
- * Maps the given location relative to the viewport origin, to a page location, allowing for zoom and pan of the canvas. This takes into account the offset of the viewport in the page so that what you get back is the mapped position relative to the target element's [left,top] corner.
583
+ * Maps the given canvas location to a page location, allowing for zoom and pan of the canvas. Note that `page` in this method takes scroll into account. If you wish to map to just the visible section of the browser, use `toWindowLocation`.
578
584
  * @param left X location
579
585
  * @param top Y location
580
586
  * @returns The mapped location, as a PointXY object.
581
- *
582
587
  */
583
588
  toPageLocation(left: number, top: number): PointXY;
589
+ /**
590
+ * Maps the given canvas location to a point, in page coordinates, relative to the surface container's origin. A return value of [0,0] from this method indicates the top left corner of the surface's container as seen by the user; negative values for x and/or y mean that the point is not in the visible viewport. Similarly, values for x greater the container width, or y greater than the container height, indicate that the point is not in the visible viewport.
591
+ *
592
+ * This method is useful when you want to position an element over the canvas at some specific canvas location. For instance, the SurfacePopup components use this to position themselves relative to the vertex they are currently referencing.
593
+ * @param left
594
+ * @param top
595
+ */
596
+ toViewportLocation(left: number, top: number): PointXY;
584
597
  /**
585
598
  * Binds to a mouse event occurring on a given model object. This is a wrapper around the `on` event binding method, which searches for an associated model object for the given event. For instance, you might have a node template that has a button inside of it that you want to respond to. When the button is clicked you want to know the node associated with the button. This method provides that. It is possible to find the associated model object yourself, via the `getObjectInfo` method of the Surface, called with the event's target, but this method does that for you.
586
599
  *
@@ -634,7 +647,7 @@ export declare class Surface extends BrowserUI<SurfaceEvents> implements Support
634
647
  /**
635
648
  * Appends an element to the viewport so that it floats above the content that is being zoomed and panned. The element will have `position:absolute` set on it. You can float any element you like, but note that the responsibility for setting an appropriate z index is yours.
636
649
  * @param el Element to float.
637
- * @param pos Position to float the element at.
650
+ * @param pos Position to float the element at. This is in page coordinates, ie. it ignores the pan/zoom of the surface, and defines a position relative to the viewport's top/left corner.
638
651
  *
639
652
  */
640
653
  floatElement(el: BrowserElement, pos: PointXY): void;
@@ -175,7 +175,7 @@ export declare class SankeyChart extends BaseChart {
175
175
  csvData?: string;
176
176
  dataType?: string;
177
177
  jsonData?: VisuallyJsDefaultJSON;
178
- }): void;
178
+ }, onload?: () => any): void;
179
179
  hasData(): boolean;
180
180
  destroy(): void;
181
181
  private _clearVertex;
@@ -209,10 +209,16 @@ export declare function linesOverlap(line1Point1: number, line1Point2: number, l
209
209
  */
210
210
  export declare function expandRectangle<T extends RectangleXY>(r: RectangleXY, deltaX: number, deltaY: number): T;
211
211
  /**
212
- * Find the intersection point of the two lines, which are treated as being of
213
- * unlimited length, ie. if both lines are of non-zero length and are not parallel, then
214
- * an intersection point is always returned even if they do not actually meet: their projections meet
215
- * at the point this method returns.
212
+ * Computes the bounding box union of two RectangleXY objects.
213
+ * This operation returns a new RectangleXY that is large enough to encompass both input rectangles.
214
+ *
215
+ * @param rect1 The first RectangleXY object.
216
+ * @param rect2 The second RectangleXY object.
217
+ * @returns A new RectangleXY object representing the union of the two input rectangles.
218
+ */
219
+ export declare function unionOfRectangles(rect1: RectangleXY, rect2: RectangleXY): RectangleXY;
220
+ /**
221
+ * Find the intersection point of the two lines, which are treated as being of unlimited length, ie. if both lines are of non-zero length and are not parallel, then an intersection point is always returned even if they do not actually meet: their projections meet at the point this method returns.
216
222
  * @param l1
217
223
  * @param l2
218
224
  * @internal
@@ -11,14 +11,19 @@ export interface CircularLayoutParameters extends LayoutParameters {
11
11
  * If true, the first node in the data set will be placed in the center of the circle. Defaults to false.
12
12
  */
13
13
  centerRoot?: boolean;
14
+ /**
15
+ * Whether or not to shift the layout so that the origin is [width/2, height/2] and not [0,0]. This is useful in situations such as groups, where elements cannot be placed in a negative position in either axis (due to there being no facility to pan the group canvas)
16
+ */
17
+ centerContent?: boolean;
14
18
  }
15
19
  /**
16
- * A layout that places vertices in a circle, optionally with one at the center.
20
+ * A layout that places vertices in a circle, optionally with one at the center, and optionally centered around [width/2, height/2] (the default origin is 0,0).
17
21
  * @group Layouts
18
22
  * @category Circular
19
23
  */
20
24
  export declare class CircularLayout extends AbstractLayout<CircularLayoutParameters> {
21
25
  private readonly _centerRoot;
26
+ private readonly _centerContent;
22
27
  static type: string;
23
28
  readonly type: string;
24
29
  padding: PointXY;
@@ -144,7 +144,7 @@ export interface GroupAddedParams {
144
144
  * @group Events
145
145
  * @category Payloads
146
146
  */
147
- export interface GroupRemovedParams {
147
+ export interface GroupRemovedParams extends VertexRemovedParams {
148
148
  /**
149
149
  * Group that was removed
150
150
  */
@@ -157,12 +157,24 @@ export interface GroupRemovedParams {
157
157
  * If children were removed, this is the list of them
158
158
  */
159
159
  children: Array<Node | Group>;
160
+ }
161
+ /**
162
+ * Base payload for a vertex removed event in the model
163
+ * @group Events
164
+ * @category Payloads
165
+ */
166
+ export interface VertexRemovedParams {
167
+ vertex: Node | Group;
168
+ /**
169
+ * List of edges that are being removed as a result of this vertex's removal.
170
+ */
171
+ edges: Array<Edge>;
160
172
  /**
161
- * If the group was a member of some other group, that group is provided here
173
+ * If the vertex was a member of some other group, that group is provided here
162
174
  */
163
175
  parentGroup?: Group;
164
176
  /**
165
- * Indicates that the group is being removed because some parent group is being removed and is forcing removal of its children.
177
+ * Indicates that the vertex is being removed because some parent group is being removed and is forcing removal of its children.
166
178
  */
167
179
  parentGroupIsBeingRemoved: boolean;
168
180
  }
@@ -171,23 +183,11 @@ export interface GroupRemovedParams {
171
183
  * @group Events
172
184
  * @category Payloads
173
185
  */
174
- export interface NodeRemovedParams {
186
+ export interface NodeRemovedParams extends VertexRemovedParams {
175
187
  /**
176
188
  * Node that was removed
177
189
  */
178
190
  node: Node;
179
- /**
180
- * List of edges that are being removed as a result of this node's removal.
181
- */
182
- edges: Array<Edge>;
183
- /**
184
- * If the node was a member of some other group, that group is provided here
185
- */
186
- parentGroup?: Group;
187
- /**
188
- * Indicates that the node is being removed because some parent group is being removed and is forcing removal of its children.
189
- */
190
- parentGroupIsBeingRemoved: boolean;
191
191
  }
192
192
  /**
193
193
  * Payload for a vertex updated event.
@@ -88,11 +88,10 @@ export interface IndexEntry {
88
88
  key: string;
89
89
  }
90
90
  /**
91
- * Index for a dataset
91
+ * Reverse text index (think Lucene). This class operates on arbitrary Javascript objects and offers a method to search the fields of all documents. By default every field is searched, but you can control which fields to search via the options you pass to the constructor.
92
92
  * @group Search
93
- * @internal
94
93
  */
95
- declare class DatasetIndex {
94
+ export declare class DatasetIndex {
96
95
  fields: Array<string>;
97
96
  root: IndexEntry;
98
97
  tokenizer: Tokenizer;
@@ -145,10 +144,10 @@ export type SearchResults = {
145
144
  ports: Array<Port>;
146
145
  };
147
146
  /**
148
- * Search index.
147
+ * Search index for a Graph. This class wraps 4 indexes - one each for nodes, groups, ports and edges, and exposes a search method that searches across each of the indexes. By default every field in the data objects is searched, but you can control that via the options you pass to the constructor.
149
148
  * @group Search
150
149
  */
151
- export declare class Index {
150
+ export declare class GraphSearchIndex {
152
151
  instance: VisuallyJsModel;
153
152
  nodeIndex: DatasetIndex;
154
153
  groupIndex: DatasetIndex;
@@ -164,4 +163,3 @@ export declare class Index {
164
163
  */
165
164
  search(value: string): SearchResults;
166
165
  }
167
- export {};
@@ -66,7 +66,7 @@ export interface SelectionOptions {
66
66
  /**
67
67
  * Optional function that can be called to fill the selection. You'd use this when you are rendering individual selections and you need to be able to refresh the whole view based on some change in the data model.
68
68
  */
69
- generator?: Function;
69
+ generator?: SelectionGenerator;
70
70
  /**
71
71
  * If true, the selection will not populate itself as soon as it is constructed. Otherwise, and this is the default behaviour, it will.
72
72
  */
@@ -82,6 +82,10 @@ export interface SelectionOptions {
82
82
  * @category Selection
83
83
  */
84
84
  export type SELECTION_EVENTS = typeof EVENT_EDGE_UPDATED | typeof EVENT_DATA_LOAD_END | typeof EVENT_DATA_LOAD_START | typeof EVENT_NODE_UPDATED | typeof EVENT_GRAPH_CLEAR_START | typeof EVENT_GROUP_UPDATED | typeof EVENT_PORT_UPDATED | typeof EVENT_EDGE_TARGET_CHANGED | typeof EVENT_EDGE_SOURCE_CHANGED | typeof EVENT_EDGE_REMOVED | typeof EVENT_EDGE_ADDED | typeof EVENT_GROUP_REMOVED | typeof EVENT_NODE_REMOVED | typeof EVENT_GROUP_ADDED | typeof EVENT_NODE_ADDED;
85
+ /**
86
+ * Defines a function that can be used as the generator for a selection.
87
+ */
88
+ export type SelectionGenerator = (s: VisuallyJsSelection, m: VisuallyJsModel) => any;
85
89
  /**
86
90
  * A selection is a group of vertices and edges, upon which you can perform bulk operations.
87
91
  * @group Model
@@ -97,7 +101,7 @@ export declare class VisuallyJsSelection extends OptimisticEventGenerator implem
97
101
  _groups: Array<Group>;
98
102
  _edges: Array<Edge>;
99
103
  capacityPolicy: string;
100
- generator: Function;
104
+ generator: SelectionGenerator;
101
105
  onReload: Function;
102
106
  onBeforeReload: Function;
103
107
  onClear: Function;
@@ -63,11 +63,11 @@ export type BeforeStartDetachInterceptor = (source: Vertex, edge: Edge) => Recor
63
63
  */
64
64
  export interface ModelOptions {
65
65
  /**
66
- * The name of a property that will exist inside the backing data for nodes/group, and which represents a list of ports pertaining to that node/group. When a node/group is rendered, if this property is set, VisuallyJs will consider the value of this property to be a list of port data object. So this property's value should be of type `Array<ObjectData>`
66
+ * The name of a property that will exist inside the backing data for nodes/group, and which represents a list of ports pertaining to that node/group. When a node/group is rendered, if this property is set, VisuallyJs will consider the value of this property to be a list of port data objects. So this property's value should be of type `Array<ObjectData>`. Note that this mechanism is fine for models where either all vertex types that have ports have them keyed with the same property, or you only have a single vertex type with ports, but for more advanced setups you should look at the `portExtractor` function.
67
67
  */
68
68
  portDataProperty?: string;
69
69
  /**
70
- * The name of a property inside of each port's data that can be used to order the ports. For instance, you might have ports that have a `rank` property, which is a number. VisuallyJs will sort the ports according to the natural ordering of this property.
70
+ * The name of a property inside of each port's data that can be used to order the ports. For instance, you might have ports that have a `rank` property, which is a number. VisuallyJs will sort the ports according to the natural ordering of this property. Note that this mechanism is fine for models where either all vertex types that have ports have them keyed with the same property, or you only have a single vertex type with ports, but for more advanced setups you should look at the `portUpdated` function.
71
71
  */
72
72
  portOrderProperty?: string;
73
73
  model?: DataModelDefinition;
@@ -235,11 +235,13 @@ export interface ModelOptions {
235
235
  /**
236
236
  * A function to use to extract an array of ports from the data representing some node/group. Whenever a node/group is rendered, VisuallyJs will use this method, if provided, to determine a list of ports for that node/group. If you use this you probably also want to define a `portUpdater`. Note that if you provide the `portDataProperty` then you do not need to set this.
237
237
  */
238
- portExtractor?: (o: ObjectData) => Array<ObjectData>;
238
+ portExtractor?: (o: ObjectData, nodeOrGroup: Node | Group) => Array<ObjectData>;
239
239
  /**
240
- * A function to use to update a given node/group's list of ports. Note that if you provide the `portDataProperty` then you do not need to set this.
240
+ * A function to use to update a given node/group's list of ports. This function should return a Javascript object which represents the node/group's backing data. This method is invoked whenever changes to some vertex's ports occur.
241
+ *
242
+ * Note that if you provide the `portDataProperty` then you do not need to set this.
241
243
  */
242
- portUpdater?: Function;
244
+ portUpdater?: (data: ObjectData, nodeOrGroup: Node | Group, ports: Array<Port>) => ObjectData;
243
245
  /**
244
246
  * Optional model event mappings to bind
245
247
  */
@@ -248,6 +250,11 @@ export interface ModelOptions {
248
250
  * Optional map of group templates to register on the model.
249
251
  */
250
252
  groupTemplates?: Record<string, GroupTemplate>;
253
+ /**
254
+ * The name of the property inside nodes/groups that identifies their parent group. This defaults to "group" but
255
+ * can be changed if it clashes with your data model.
256
+ */
257
+ groupProperty?: string;
251
258
  }
252
259
  /**
253
260
  * Definition of a model event callback.
@@ -395,13 +402,14 @@ export declare abstract class VisuallyJsModel extends OptimisticEventGenerator i
395
402
  typeProperty: string;
396
403
  edgeTypeProperty: string;
397
404
  portTypeProperty: string;
405
+ groupProperty: string;
398
406
  typeFunction: TypeFunction;
399
407
  edgeIdFunction: IdFunction;
400
408
  edgeTypeFunction: TypeFunction;
401
409
  portIdFunction: IdFunction;
402
410
  portTypeFunction: TypeFunction;
403
- portExtractor: Function;
404
- portUpdater: Function;
411
+ portExtractor: (o: ObjectData, nodeOrGroup: Node | Group) => Array<ObjectData>;
412
+ portUpdater: (data: ObjectData, nodeOrGroup: Node | Group, ports: Array<Port>) => ObjectData;
405
413
  portDataProperty: string;
406
414
  portOrderProperty: string;
407
415
  modelTopAttribute: string;