Options
Public/Protected
  • Public
  • Public/Protected
  • All
Menu

GoJS API 文档

Hierarchy

  • Margin

A Margin represents a band of space outside or inside a rectangular area, with possibly different values on each of the four sides.

Example uses include GraphObject.margin, Panel.padding, and Diagram.padding.

Use the static functions Margin.parse and Margin.stringify to convert to and from a standard string representation that is independent of the current locale.

When an instance of this class is the value of a property of a GraphObject class or Diagram or CommandHandler or a Tool class, you should treat the object as if it were frozen or read-only -- you cannot modify its properties. This allows the property to return a value without allocating a new instance. If you need to do your own calculations with the value, call copy to make a new instance with the same values that you can modify.

Many methods modify the object's properties and then return a reference to "this" object. The only instance method to allocate a new object is the copy method. The static Margin.parse method also allocates a new object.

The "Debug" implementation of this class is significantly slower than the "Release" implementation, mostly due to additional error checking.

You cannot inherit from this class.

Index

Constructors

constructor

  • new Margin(t?: number, r?: number, b?: number, l?: number): Margin
  • If zero arguments are supplied, zero is used for all four sides. If one argument is supplied, that number is used for all four sides. If two arguments are supplied, the top and bottom sides get the first value, and the left and right sides get the second value. Otherwise there must be four arguments, in the order: top, right, bottom, left.

    Parameters

    • Optional t: number

      the margin for the top side; if not supplied, all sides are zero.

    • Optional r: number

      the margin for the right side; if not supplied, all sides have the value of the first argument.

    • Optional b: number

      the margin for all bottom side; if not supplied, the top and bottom get the value of the first argument, and the right and left sides get the value of the second argument.

    • Optional l: number

      the margin for the left side; must be supplied if the third argument was supplied.

    Returns Margin

Properties

bottom : number

  • Gets or sets the bottom value of this margin. Default is 0.

left : number

  • Gets or sets the left value of this margin. Default is 0.

right : number

  • Gets or sets the right value of this margin. Default is 0.

top : number

  • Gets or sets the top value of this margin. Default is 0.

Methods

Virtual copy

  • Create a copy of this Margin, with the same values.

    Returns Margin

equalTo

  • equalTo(t: number, r: number, b: number, l: number): boolean
  • Indicates whether the given margin is equal to this Margin.

    see

    equals

    Parameters

    • t: number

      top.

    • r: number

      right.

    • b: number

      bottom.

    • l: number

      left.

    Returns boolean

    True if the two Margins have identical Top and Right and Bottom and Left values, false otherwise.

equals

  • Indicates whether the given Margin is equal to this Margin.

    see

    equalTo

    Parameters

    • m: Margin

      The Margin to compare to this Margin.

    Returns boolean

    True if the two Margins have identical Top and Right and Bottom and Left values, false otherwise.

isReal

  • isReal(): boolean
  • True if this Margin has values that are real numbers and not infinity.

    Returns boolean

Static parse

  • This static function can be used to read in a Margin from a string that was produced by Margin.stringify.

    go.Margin.parse("1 2 3 4") produces the Margin new go.Margin(1, 2, 3, 4).

    Parameters

    • str: string

    Returns Margin

set

  • Modify this Margin so that its Top, Right, Bottom, and Left values are the same as the given Margin.

    Parameters

    Returns Margin

    this.

setTo

  • setTo(t: number, r: number, b: number, l: number): Margin
  • Modify this Margin with new Top, Right, Bottom, and Left values.

    Parameters

    • t: number

      top.

    • r: number

      right.

    • b: number

      bottom.

    • l: number

      left.

    Returns Margin

    this.

Static stringify

  • stringify(val: Margin): string
  • This static function can be used to write out a Margin as a string that can be read by Margin.parse.

    go.Margin.stringify(new go.Margin(1, 2, 3, 4)) produces the string "1 2 3 4".

    Parameters

    Returns string

加入 GoJS 交流群
GoJS 交流群 (769862113)