File

src/lib/models/cut.model.ts

Description

Cut for specifying filters on event data attribute.

Index

Properties
Methods

Constructor

constructor(field: string, minValue: number, maxValue: number, step: number, minCutActive: boolean, maxCutActive: boolean)

Create the cut to filter an event data attribute.

Parameters :
Name Type Optional Description
field string No

Name of the event data attribute to be filtered.

minValue number No

Minimum allowed value of the event data attribute.

maxValue number No

Maximum allowed value of the event data attribute.

step number No

Size of increment when using slider.

minCutActive boolean No

If true, the minimum cut is appled. Can be overriden later with enableMinCut.

maxCutActive boolean No

If true, the maximum cut is appled. Can be overriden later with enableMaxCut.

Properties

Private defaultApplyMaxValue
Type : boolean

Default if upper bound applied

Private defaultApplyMinValue
Type : boolean

Default if lower bound applied

Private defaultMaxValue
Type : number

Default maximum allowed value of the event data attribute.

Private defaultMinValue
Type : number

Default minimum allowed value of the event data attribute.

Public field
Type : string
Name of the event data attribute to be filtered.
Public maxCutActive
Type : boolean
Default value : true
If true, the maximum cut is appled. Can be overriden later with enableMaxCut.
Public maxValue
Type : number
Maximum allowed value of the event data attribute.
Public minCutActive
Type : boolean
Default value : true
If true, the minimum cut is appled. Can be overriden later with enableMinCut.
Public minValue
Type : number
Minimum allowed value of the event data attribute.
Public step
Type : number
Default value : 1
Size of increment when using slider.

Methods

cutPassed
cutPassed(value: number)

Returns true if the passed value is within the active cut range.

Parameters :
Name Type Optional
value number No
Returns : boolean
enableMaxCut
enableMaxCut(check: boolean)

Returns true if upper cut is valid.

Parameters :
Name Type Optional
check boolean No
Returns : void
enableMinCut
enableMinCut(check: boolean)

Returns true if upper cut is valid.

Parameters :
Name Type Optional
check boolean No
Returns : void
reset
reset()

Reset the minimum and maximum value of the cut to default.

Returns : void
export class Cut {
  /** Default minimum allowed value of the event data attribute. */
  private defaultMinValue: number;
  /** Default maximum allowed value of the event data attribute. */
  private defaultMaxValue: number;
  /** Default if upper bound applied */
  private defaultApplyMaxValue: boolean;
  /** Default if lower bound applied */
  private defaultApplyMinValue: boolean;
  /**
   * Create the cut to filter an event data attribute.
   * @param field Name of the event data attribute to be filtered.
   * @param minValue Minimum allowed value of the event data attribute.
   * @param maxValue Maximum allowed value of the event data attribute.
   * @param step Size of increment when using slider.
   * @param minCutActive If true, the minimum cut is appled. Can be overriden later with enableMinCut.
   * @param maxCutActive If true, the maximum cut is appled. Can be overriden later with enableMaxCut.
   *
   */
  constructor(
    public field: string,
    public minValue: number,
    public maxValue: number,
    public step: number = 1,
    public minCutActive: boolean = true,
    public maxCutActive: boolean = true,
  ) {
    this.defaultMinValue = minValue;
    this.defaultMaxValue = maxValue;
    this.defaultApplyMinValue = minCutActive;
    this.defaultApplyMaxValue = maxCutActive;
  }

  /** Returns true if upper cut is valid. */
  enableMaxCut(check: boolean) {
    this.maxCutActive = check;
  }

  /** Returns true if upper cut is valid. */
  enableMinCut(check: boolean) {
    this.minCutActive = check;
  }

  /** Returns true if the passed value is within the active cut range. */
  cutPassed(value: number): boolean {
    return (
      (!this.maxCutActive || value <= this.maxValue) &&
      (!this.minCutActive || value > this.minValue)
    );
  }

  /**
   * Reset the minimum and maximum value of the cut to default.
   */
  reset() {
    this.minValue = this.defaultMinValue;
    this.maxValue = this.defaultMaxValue;
    this.minCutActive = this.defaultApplyMinValue;
    this.maxCutActive = this.defaultApplyMaxValue;
  }
}

results matching ""

    No results matching ""