/*
 * @Description  : 
 * @Version      : 1.0
 * @Author       : Shiming
 * @Date         : 2022-04-06 14:32:03
 * @LastEditors  : Shiming
 * @LastEditTime : 2022-04-18 14:25:25
 * @FilePath     : \\tms-obc-web\\src\\app\\routes\\datatable\\components\\busitable\\pillar\\pillar.component.ts
 * Copyright (C) 2022 huzhenhong. All rights reserved.
 */
import { Component, ElementRef, Input, NgZone, OnChanges, OnInit, SimpleChanges, ViewChild } from '@angular/core';
import { Chart } from '@antv/g2';
import { DataService } from 'src/app/routes/datatable/services/data.service';
@Component({
  selector: 'app-busitable-pillar',
  templateUrl: './pillar.component.html',
  styleUrls: ['./pillar.component.less']
})
export class BusitablePillarComponent implements OnInit, OnChanges {
  el: any;
  @Input() chartData: any;
  chart: any;
  constructor(private service: DataService, private ngZone: NgZone) {

  }
  ngOnChanges(changes: SimpleChanges): void {
    if (this.chartData) {
      // setTimeout(()=>{
      //   this.chart.render(true)
      // }, 1000)

    }
  }

  ngOnInit(): void {

  }
  reRender() {
      this.chart.data(this.chartData);
      this.chart.render();
  }
  render(el: ElementRef<HTMLDivElement>): void {
    this.el = el.nativeElement
    setTimeout(() => {
      this.ngZone.runOutsideAngular(() => this.init(this.el));
      }, 500)
  }

  private init(el: HTMLElement): void {
    this.chart = new Chart({
      container: el,
      autoFit: true,
      height: 500,
    });

    this.chart.data(this.chartData);

    const itemTpl = `
        <div style="padding: 15px; color: red">
            业绩量:&nbsp;&nbsp;{value}
        </div>
`
    this.chart.tooltip({
      showTitle: true,
      showMarkers: false,
      itemTpl: itemTpl
  });
    this.chart.interval().position('time*number');
    this.chart.render();
  }

}