Options
All
  • Public
  • Public/Protected
  • All
Menu

PanelLayout类

层次结构

  • PanelLayout

这是所有面板布局的抽象基类,它告知可能的面板类型。可以通过创建PanelLayout的子类来创建自己的Panel类型,尽管这并不常见,不建议初学者使用

默认情况下, GoJS具有12种面板类型,每种类型对应于PanelLayout子类:

  • 'Position', PanelLayoutPosition
  • 'Horizontal', PanelLayoutHorizontal
  • 'Vertical', PanelLayoutVertical
  • 'Spot', PanelLayoutSpot
  • 'Auto', PanelLayoutAuto
  • 'Table', PanelLayoutTable
  • 'Viewbox', PanelLayoutViewbox
  • 'TableRow', PanelLayoutTableRow
  • 'TableColumn', PanelLayoutTableColumn
  • 'Link', PanelLayoutLink
  • 'Grid', PanelLayoutGrid
  • 'Graduated', PanelLayoutGraduated

这些默认包含在 go.jsgo-debug.js 的构建中。 从源构建时,可以选择排除所有其他对象,但 Position, Vertical, Auto, Link, 和 Grid 除外。 在/projects 文件夹中的 minimalSourcemaximalSource 对此进行了演示。

通过调用静态函数 Panel.definePanelLayout 来添加新的Layout:

Panel.definePanelLayout('Table', new PanelLayoutTable());

每个PanelLayout定义一个 measurearrange 例程。 measure例程必须使用Panel的每个元素调用 measureElement , 而 arrange 例程必须类似的使用Panel的每个元素调用 arrangeElement

PanelLayout示例中有一个 PanelLayout 示例

since

2.0

Index

Constructors

constructor

Methods

Virtual arrange

  • 根据面板及其元素列表,排列每个元素

    这必须为每个Panel元素调用 arrangeElement ,这将设置该元素的 GraphObject.actualBounds

    对于某些元素的排列,知道每个元素的统一面积是很有用的,此Rect可用于在区域内将元素右对齐或居中对齐

    Parameters

    • panel: Panel

      Panel叫做布局

    • elements: Array<GraphObject>

      Panel元素数组

    • union: Rect

      矩形, 如果 measure 正确的构造, 其中包含面板中每个元素的预期联合边界。

    Returns void

Protected arrangeElement

  • arrangeElement(obj: GraphObject, fx: number, fy: number, fw: number, fh: number, clipRect?: Rect): void
  • Arranges the GraphObject onto its parent Panel. The passed-in numbers typically account for GraphObject.margin and other offsets. This sets GraphObject.actualBounds.

    Parameters

    • obj: GraphObject

      GraphObject to be arranged.

    • fx: number

      The final x value of actualBounds that the Panel computes for the GraphObject.

    • fy: number

      The final y value of actualBounds that the Panel computes for the GraphObject.

    • fw: number

      The final width value of actualBounds that the Panel computes for the GraphObject.

    • fh: number

      The final height value of actualBounds that the Panel computes for the GraphObject.

    • Optional clipRect: Rect

      an optional area to constrain this actualBounds to when picking and drawing. By default, this is only used with Fixed/Table panels element, provided as a Rect.

    Returns void

Virtual measure

  • measure(panel: Panel, width: number, height: number, elements: Array<GraphObject>, union: Rect, minw: number, minh: number): void
  • Given the available size, measure the Panel and determine its expected drawing size. Sets the measuredBounds of the object.

    This must call measureElement with each Panel element.

    This must also construct the union.width and union.height of the passed in union Rect argument. This union must reflect the measured size of the panel.

    Parameters

    • panel: Panel

      Panel which called this layout

    • width: number

      expected width of the panel

    • height: number

      expected height of the panel

    • elements: Array<GraphObject>

      Array of Panel elements

    • union: Rect

      rectangle to contain the expected union bounds of every element in the Panel. Useful for arrange.

    • minw: number

      minimum width of the panel

    • minh: number

      minimum height of the panel

    Returns void

Protected measureElement

  • measureElement(obj: GraphObject, width: number, height: number, minw: number, minh: number): void
  • Given the available size, measure one element of the Panel and determine its expected drawing size. Sets the measuredBounds of the object.

    Parameters

    • obj: GraphObject

      Panel which called this layout

    • width: number

      expected width of the GraphObject

    • height: number

      expected height of the GraphObject

    • minw: number

      minimum width of the GraphObject

    • minh: number

      minimum height of the GraphObject

    Returns void