igniteui-angular-sovn
Version:
Ignite UI for Angular is a dependency-free Angular toolkit for building modern web apps
145 lines (121 loc) • 3.6 kB
text/typescript
import { Component, Input, TemplateRef, HostBinding } from '@angular/core';
import { TicksOrientation, TickLabelsOrientation } from '../slider.common';
import { NgFor, NgClass, NgTemplateOutlet } from '@angular/common';
/**
* @hidden
*/
export class IgxTicksComponent {
public primaryTicks: number;
public secondaryTicks: number;
public primaryTickLabels: boolean;
public secondaryTickLabels: boolean;
public ticksOrientation: TicksOrientation;
public tickLabelsOrientation: TickLabelsOrientation;
public maxValue: number;
public minValue: number;
public labelsViewEnabled: boolean;
public labels: Array<number | string | boolean | null | undefined>;
public tickLabelTemplateRef: TemplateRef<any>;
/**
* @hidden
*/
public ticksClass = true;
/**
* @hidden
*/
public get ticksTopClass() {
return this.ticksOrientation === TicksOrientation.Top;
}
/**
* @hidden
*/
public get hasPrimaryClass() {
return this.primaryTicks > 0;
}
/**
* @hidden
*/
public get labelsTopToBottomClass() {
return this.tickLabelsOrientation === TickLabelsOrientation.TopToBottom;
}
/**
* @hidden
*/
public get labelsBottomToTopClass() {
return this.tickLabelsOrientation === TickLabelsOrientation.BottomToTop;
}
/**
* Returns the template context corresponding to
* {@link IgxTickLabelTemplateDirective}
*
* ```typescript
* return {
* $implicit //returns the value per each tick label.
* isPrimery //returns if the tick is primary.
* labels // returns the {@link labels} collection.
* index // returns the index per each tick of the whole sequence.
* }
* ```
*
* @param idx the index per each tick label.
*/
public context(idx: number): any {
return {
$implicit: this.tickLabel(idx),
isPrimary: this.isPrimary(idx),
labels: this.labels,
index: idx
};
}
/**
* @hidden
*/
public get ticksLength() {
return this.primaryTicks > 0 ?
((this.primaryTicks - 1) * this.secondaryTicks) + this.primaryTicks :
this.secondaryTicks > 0 ? this.secondaryTicks : 0;
}
public hiddenTickLabels(idx: number) {
return this.isPrimary(idx) ? this.primaryTickLabels : this.secondaryTickLabels;
}
/**
* @hidden
*/
public isPrimary(idx: number) {
return this.primaryTicks <= 0 ? false :
idx % (this.secondaryTicks + 1) === 0;
}
/**
* @hidden
*/
public tickLabel(idx: number) {
if (this.labelsViewEnabled) {
return this.labels[idx];
}
const labelStep = (Math.max(this.minValue, this.maxValue) - Math.min(this.minValue, this.maxValue)) / (this.ticksLength - 1);
const labelVal = labelStep * idx;
return (this.minValue + labelVal).toFixed(2);
}
}