projects/wms-framework/src/lib/models/controls/ThicknessModel.ts
Represents the thickness of the area around a rectangle.
Properties |
Methods |
constructor(p1?: number, p2?: number, p3?: number, p4?: number)
|
Public Bottom |
Type : number
|
Public Left |
Type : number
|
Public Right |
Type : number
|
Public Top |
Type : number
|
Static parse | ||||||
parse(input: string | ThicknessModel)
|
||||||
Returns a Thickness from a string, or
Parameters :
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}`;
}
}