File

src/module/graph-axis/graph-axis.component.ts

Implements

OnInit

Metadata

selector graph-axis
styleUrls graph-axis.component.scss
templateUrl ./graph-axis.component.html

Index

Methods
Inputs

Constructor

constructor()

Inputs

formatTickFn

Type: function

label

Type: string | undefined

position

Type: AxisPosition

scale

Type: Scale

Methods

Public getOrientation
getOrientation()
Returns : Orientation
Public getTicks
getTicks()
Returns : string[]
ngOnInit
ngOnInit()
Returns : void
import { Scale, AxisPosition, Orientation } from './../../types';
import {Component, Input, OnInit} from '@angular/core';
import * as R from 'ramda';
import {round, scale} from '../../utilities/misc-utils';

@Component({
  selector: 'graph-axis',
  templateUrl: './graph-axis.component.html',
  styleUrls: ['./graph-axis.component.scss']
})
export class GraphAxisComponent implements OnInit {

  @Input()
  public label: string | undefined;

  @Input()
  public scale: Scale;

  @Input()
  public position: AxisPosition;

  @Input()
  public formatTickFn: (val: number) => string = R.pipe(
    (i: number) => round(i, 2),
    R.toString
  );

  constructor() { }

  ngOnInit() {
  }

  public getOrientation(): Orientation {
    if(R.contains(this.position, ['top', 'bottom'])){
      return 'horizontal';
    } else {
      return 'vertical';
    }
  }

  // returns an array of formatted tick values
  public getTicks(): string[] {
    return scale(this.scale.min, this.scale.max, this.scale.numTicks)
      .map(this.formatTickFn);
  }
}
<div class="axis" [ngClass]="['axis--' + getOrientation(), 'axis--' + position]">
  <div class="axis__label-container">
    <span class="axis__label" *ngIf="label">{{label}}</span>
  </div>
  <div class="axis__ticks">
    <span *ngFor="let tick of getTicks()" class="axis__tick-container">
      <span class="axis__tick">{{tick}}</span>
    </span>
  </div>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""