GoJS API
/ to search
    Preparing search index...

    Class Size

    A Size describes a width and a height in two-dimensional coordinates. The width and height must both be non-negative.

    Use the static functions Size.parse and Size.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 Size.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

    • The default constructor produces the Size(0,0). This constructor may take either zero arguments or two arguments.

      Parameters

      • Optionalw: number

        The initial width (must be non-negative).

      • Optionalh: number

        The initial height (must be non-negative).

      Returns Size

    Accessors

    • get height(): number

      Gets or sets the height value of the Size. The value must not be negative.

      Returns number

    • get width(): number

      Gets or sets the width value of the Size. The value must not be negative.

      Returns number

    Methods

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

      Returns Size

    • Indicates whether the given Size is equal to the current Size.

      Parameters

      • s: Size

        The Size to compare to the current Size.

      Returns boolean

      True if the Sizes have the same width and height, false otherwise.

    • Indicates whether the given size is equal to this Size.

      Parameters

      • w: number

        the width.

      • h: number

        the height.

      Returns boolean

      True if the Sizes have the same width and height, false otherwise.

      see

      equals

    • Modify this Size so that its width and height are changed by the given distances. When the arguments are negative, this operation deflates this Size, but not beyond zero.

      Parameters

      • w: number

        The additional width, which must be a real number; may be negative.

      • h: number

        The additional height, which must be a real number; may be negative.

      Returns Size

      this.

    • True if this Size has Width and Height values that are real numbers and not infinity.

      Returns boolean

    • Modify this Size so that its Width and Height values are the same as the given Size.

      Parameters

      • s: Size

        the given Size.

      Returns this

      this.

    • Modify this Size with new Width and Height values.

      Parameters

      • w: number

        the width.

      • h: number

        the height.

      Returns this

      this.

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

      go.Size.parse("1 2") produces the Size new go.Size(1, 2).

      Parameters

      • str: string

      Returns Size

    • This static function can be used to write out a Size as a string that can be read by Size.parse.

      go.Size.stringify(new go.Size(1, 2)) produces the string "1 2".

      Parameters

      Returns string

    • This static function returns a function that can be used as a back converter for a Binding to write out a Size's values as numbers with a fixed number of digits after the decimal point.

      This is useful for limiting the size of JSON output and making it more legible. It might also be useful for regression testing.

      Example:

        new go.Binding("desiredSize", "size", go.Size.parse, go.Size.stringifyFixed(1))
      

      Parameters

      • digits: number

        must be a non-negative integer

      Returns (val: Size) => string

      a function that converts a Size to a string without so many decimals

      since

      3.0