File

projects/wms-framework/src/lib/models/controls/ThicknessModel.ts

Description

Represents the thickness of the area around a rectangle.

Index

Properties
Methods

Constructor

constructor(p1?: number, p2?: number, p3?: number, p4?: number)
Parameters :
Name Type Optional
p1 number Yes
p2 number Yes
p3 number Yes
p4 number Yes

Properties

Public Bottom
Type : number
Public Left
Type : number
Public Right
Type : number
Public Top
Type : number

Methods

Static parse
parse(input: string | ThicknessModel)

Returns a Thickness from a string, or null if the string format is incorrect.

Parameters :
Name Type Optional
input string | ThicknessModel No
Returns : ThicknessModel

{ThicknessModel}

toString
toString()

Returns a string representation of the thickness.

Returns : string

{string}

export class ThicknessModel {
  public Left: number;
  public Top: number;
  public Right: number;
  public Bottom: number;

  /**
   * Creates an instance of ThicknessModel.
   *
   * @memberof ThicknessModel
   */
  constructor();
  // eslint-disable-next-line @typescript-eslint/unified-signatures
  constructor(uniform: number);
  constructor(left: number, top: number, right: number, bottom: number);
  constructor(p1?: number, p2?: number, p3?: number, p4?: number) {
    if (
      typeof p1 === 'number' &&
      typeof p2 === 'number' &&
      typeof p3 === 'number' &&
      typeof p4 === 'number'
    ) {
      this.Left = p1;
      this.Top = p2;
      this.Right = p3;
      this.Bottom = p4;
    } else if (typeof p1 === 'number') {
      this.Left = p1;
      this.Top = p1;
      this.Right = p1;
      this.Bottom = p1;
    } else {
      this.Left = 0;
      this.Top = 0;
      this.Right = 0;
      this.Bottom = 0;
    }
  }

  /**
   * Returns a Thickness from a string, or `null` if the string format is incorrect.
   *
   * @static
   * @param {(string | ThicknessModel)} input
   * @return {*}  {ThicknessModel}
   * @memberof ThicknessModel
   */
  // eslint-disable-next-line @typescript-eslint/naming-convention
  static parse(input: string | ThicknessModel): ThicknessModel {
    /* istanbul ignore else */
    if (input == null) {
      return null;
    }
    /* istanbul ignore else */
    if (input instanceof ThicknessModel) {
      return new ThicknessModel(
        input.Left,
        input.Top,
        input.Right,
        input.Bottom
      );
    }

    let result: ThicknessModel = null;
    const parts = input.toString().split(',');
    const margins = parts.map((v) => parseFloat(v));
    /* istanbul ignore else */
    if (parts.length === 1) {
      result = new ThicknessModel(margins[0]);
    } else if (parts.length === 2) {
      result = new ThicknessModel(
        margins[0],
        margins[1],
        margins[0],
        margins[1]
      );
    } else if (parts.length >= 4) {
      result = new ThicknessModel(
        margins[0],
        margins[1],
        margins[2],
        margins[3]
      );
    }

    return result;
  }

  /**
   * Returns a string representation of the thickness.
   *
   * @return {*}  {string}
   * @memberof ThicknessModel
   * @wMethod ToString
   */
  // eslint-disable-next-line @typescript-eslint/naming-convention
  toString(): string {
    return `${this.Left},${this.Top},${this.Right},${this.Bottom}`;
  }
}

result-matching ""

    No results matching ""